[英]Python: using twittersearch api to get twitter.retweeted.id
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. 我正在尝试使用twittersearch api获得被转发的原始tweet的ID(请参阅文档: http ://dev.datasift.com/docs/sources/public-sources/twitter),但收效甚微。 I want to use twitter search to to specifically get: twitter.retweeted.id 我想使用Twitter搜索来专门获取: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? 反正有通过twittersearch得到这个吗? if not: anyone with experience on how to retrieve it via twython? 如果不是:有经验的人如何通过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 因此,您只需要为推文编写一个单独的循环
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.