Reputation: 181
I use TwitterAPI to extract twitter data, but I have an SyntaxError: invalid Syntax when I run python. I'm not a coding expert. Anyone can help me to figure out?´
for page in api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL), {'query'=keyword, count=200, include_rts=False, since=start_date}).pages(50):
for status in page:
new_entry = []
status = status._json
``
Upvotes: 3
Views: 463
Reputation: 4058
There are few problems with your code. Here is an improved version of it:
for status in api.request('tweets/search/%s/:%s' % (PRODUCT, LABEL),
{'query'=keyword, 'count'=100, 'include_rts'=False, 'since'=start_date}):
# "status" returned by api.request is already a json object
# so you can print the screen name and text from the status like this:
print(status['user']['screen_name'] + ":" + status['text'])
Outline of my changes:
I changed the variable name page
to status
, for clarity, since api.request
returns an iterator that returns statuses.
Just as you did with the key name query
, all names must be quoted.
The maximum value of count
is 100.
The object returned by api.request has no method called pages
. If you want to get successive pages of tweets, you should look at this example https://github.com/geduldig/TwitterAPI/blob/master/examples/page_tweets.py
Upvotes: 2