Tweepy 中 Twitter 状态的转推者 [英] Retweeters of a Twitter status in Tweepy

查看:30
本文介绍了Tweepy 中 Twitter 状态的转推者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是这个问题的后续问题.我想获取转发特定推文的用户的 ID.

我尝试遵循相同的技术,但出现错误.代码如下:

导入tweepyauth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)api = tweepy.API(auth)firstTweet = api.user_timeline("github")[0]打印第一个Tweet.text打印 firstTweet.id结果 = api.retweeted_by(firstTweet.id)打印结果

这将返回第一条推文以及推文 ID.然后它给了我以下错误:

 回溯(最近一次调用最后一次): 中的文件twitter_test.py",第 21 行结果 = api.retweeted_by("357237988863913984")文件/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py",第197行,在_call返回方法.execute()文件/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py",第173行,在执行引发 TweepError(error_msg, resp)tweepy.error.TweepError: [{u'message': u'Sorry, that page does not exist', u'code': 34}]

解决方案

retweeted_by 不是 1.1 twitter API 的一部分.切换到转推:

results = api.retweets(firstTweet.id)

仅供参考,引用自 docs:><块引用>

获取状态/转发者/ID

返回最多 100 个用户 ID 的集合,这些用户 ID 属于以下用户:转发了 id 参数指定的推文.

此方法提供与 GET statuses/retweets/:id 类似的数据和替换 API v1 的 GET statuses/:id/retweeted_by/ids 方法.

This is kindof a followup question to this question. I want to get the ID of the users that have retweeted a particular tweet.

I tried following the same technique but I'm getting an error. Here's the code:

import tweepy

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)

api = tweepy.API(auth)

firstTweet = api.user_timeline("github")[0]
print firstTweet.text
print firstTweet.id
results = api.retweeted_by(firstTweet.id) 
print results

This returns the 1st tweet and also the tweet ID. It then gives me the following error:

    Traceback (most recent call last):
  File "twitter_test.py", line 21, in <module>
    results = api.retweeted_by("357237988863913984") 
  File "/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py", line 197, in _call
    return method.execute()
  File "/usr/local/lib/python2.7/dist-packages/tweepy-2.1-py2.7.egg/tweepy/binder.py", line 173, in execute
    raise TweepError(error_msg, resp)
tweepy.error.TweepError: [{u'message': u'Sorry, that page does not exist', u'code': 34}]

解决方案

retweeted_by is not a part of 1.1 twitter API. Switch to retweets:

results = api.retweets(firstTweet.id)

FYI, quote from docs:

GET statuses/retweeters/ids

Returns a collection of up to 100 user IDs belonging to users who have retweeted the tweet specified by the id parameter.

This method offers similar data to GET statuses/retweets/:id and replaces API v1's GET statuses/:id/retweeted_by/ids method.

这篇关于Tweepy 中 Twitter 状态的转推者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆