I am trying to get the id of the original tweet that was retweeted (see docs: http://dev.datasift.com/docs/sources/public-sources/twitter ) using the twittersearch api with little result. I want to use twitter search to to specifically get: twitter.retweeted.id
This is my code:
import datetime
import csv
import itertools as it
import codecs
tweet_text_id = []
from TwitterSearch import TwitterSearchOrder, TwitterUserOrder, TwitterSearchException, TwitterSearch
try:
tso = TwitterSearchOrder()
tso.set_keywords([""])
tso.set_language('')
tso.set_include_entities(True)
ts = TwitterSearch(
consumer_key = "aaa",
consumer_secret = "bbb",
access_token = "ccc",
access_token_secret = "dddd"
)
for tweet in ts.search_tweets_iterable(tso):
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : tweet ['retweeted']['id']})
for i in tweet_text_id:
print(i)
except TwitterSearchException as e:
print(e)
I get the following error:
TypeError: 'bool' object has no attribute '__getitem__'
I've also tried:
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : tweet['retweeted'_'id']})
and:
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : retweeted['id']})
Is there anyway to get this via twittersearch? if not: anyone with experience on how to retrieve it via twython?
Thanks!
found it :
it should be:
for retweeted in ts.search_tweets_iterable(tso):
tweet_text_id.append({'retweeted' : retweeted['id']})
doing this:
for retweeted, tweet in ts.search_tweets_iterable(tso):
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : tweet ['retweeted']['id']})
results in this error:
ValueError: too many values to unpack
So you just have to write a seperate loop for tweet
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.