문제

I'm trying to programmatically retweet various tweets with Python's python-twitter library. The code executes without error, but the RT never happens. Here's the code:

from twitter import Twitter, OAuth

# my actual keys are here
OAUTH_TOKEN = ""
OAUTH_SECRET = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""

t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
        CONSUMER_KEY, CONSUMER_SECRET))

result = t.statuses.retweets._id(_id=444320020122722304)

print(result)

The only output is an empty list. How can I get it to actually RT the tweet?

도움이 되었습니까?

해결책 2

All of the answers posted here were instrumental in finding the final code that works. Thank you all! The code that works with the python-twitter library is below.

from twitter import Twitter, OAuth

# my actual keys are here
OAUTH_TOKEN = ""
OAUTH_SECRET = ""
CONSUMER_KEY = ""
CONSUMER_SECRET = ""

t = Twitter(auth=OAuth(OAUTH_TOKEN, OAUTH_SECRET,
        CONSUMER_KEY, CONSUMER_SECRET))

result = t.statuses.retweet(id=444320020122722304)

print(result)

다른 팁

answer using tweepy:

import tweepy

CONSUMER_KEY = ''
CONSUMER_SECRET = ''
ACCESS_KEY = ''
ACCESS_SECRET = ''

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET)
api = tweepy.API(auth)
api.retweet(tweetID)  # e.g. api.retweet(445959276855435264)

# or for use from command line:
# api.retweet(sys.argv[1])

hope that helps? I'm guessing my ACCESS key and secret are equivalent to your OAUTH token and secret..

You don't mention but I'm assuming you're using python-twitter library:

Try using (from the doc) def PostRetweet(self, original_id, trim_user=False)

Check out Twython's retweet function under Core Interface here https://twython.readthedocs.org/en/latest/api.html and the associated Twitter API https://dev.twitter.com/docs/api/1.1/post/statuses/retweet/%3Aid documents.

Also this post on here Posting a retweet via twython gives 401 whereas I can easily access the timeline.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top