我正在尝试以编程方式转发使用Python python-twitter
库的各种推文。代码执行没有错误,但RT永远不会发生。这是代码:
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)
唯一的输出是空列表。我怎样才能让它实际转发推文?
答案 0 :(得分:2)
使用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])
希望有帮助吗?我猜测我的ACCESS密钥和秘密等同于你的OAUTH令牌和秘密......
答案 1 :(得分:2)
此处发布的所有答案都有助于找到有效的最终代码。谢谢你们!与python-twitter
库一起使用的代码如下所示。
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)
答案 2 :(得分:1)
你不提,但我假设你正在使用python-twitter库:
尝试使用(来自doc)
def PostRetweet(self, original_id, trim_user=False)
答案 3 :(得分:1)