简体   繁体   中英

Using the twitter API and Python to obatain retweeter's id

I have an issue that has been bothering for a while now, and which I have tried really hard to fix but have found no solution. So I'm doing an internship doing research on complex networks, nothing business-oriented, it's mostly physics and network theory research that they are doing. So what I'm doing is writing scripts for them to obtain data from twitter and tumblr (such as friend lists, and retweets) and then then graphing the user-to-user relations.

Anyways, going straight to my problem, I have already written my script pretty much, mainly using the twitter-python wrapper. However, none of the wrappers for python has any way of using the GET statuses/retweets/:id which returns the 100 first retweeter's ids. I've looked through all different twitter libraries for python and could not find anything. I found tweety for MATLAB but I'm using Ubuntu and it hasn't been easy to obtain.

So my question is, how can I implement this API myself, without a wrapper? is there any wrapper, even in another language that you guys would know allows me to do this? I wouldn't mind getting the retweet information in a file and then using my python script to go over it and get the information I need.

Thank you very much! This is the resource I wanna use: https://dev.twitter.com/docs/api/1.1/get/statuses/retweets/%3Aid

EDIT: So with tweepy this is what I'm trying to do

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET)

tweet = auth.retweets(TWEET_ID)

print json.dumps(tweet, indent=1)

Looks like tweepy should work for you. See docs and source .

Example:

import tweepy

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(key, secret)

api = tweepy.API(auth)

public_tweets = api.search("stackoverflow")
for tweet in public_tweets:
    print api.retweets(tweet.id)

Hope that helps.

好的,我弄清楚了,在执行循环而不是打印转推时,我打印了retweets.uset.screen_name我很傻,谢谢大家的帮助

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM