[英]Python: using twittersearch api to get twitter.retweeted.id
我正在嘗試使用twittersearch api獲得被轉發的原始tweet的ID(請參閱文檔: http ://dev.datasift.com/docs/sources/public-sources/twitter),但收效甚微。 我想使用Twitter搜索來專門獲取:twitter.retweeted.id
這是我的代碼:
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)
我收到以下錯誤:
TypeError: 'bool' object has no attribute '__getitem__'
我也嘗試過:
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : tweet['retweeted'_'id']})
和:
tweet_text_id.append({'id':tweet['id'], 'text': tweet['text'].encode('utf8'), 'retweeted' : retweeted['id']})
反正有通過twittersearch得到這個嗎? 如果不是:有經驗的人如何通過twython檢索它嗎?
謝謝!
找到了 :
它應該是:
for retweeted in ts.search_tweets_iterable(tso):
tweet_text_id.append({'retweeted' : retweeted['id']})
這樣做:
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']})
導致此錯誤:
ValueError: too many values to unpack
因此,您只需要為推文編寫一個單獨的循環
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.