要通过tweepy发布新推文,我已使用以下代码
#Twitter credentials - Augrav
access_token = config.get('twitter_credentials', 'access_token')
access_token_secret = config.get('twitter_credentials', 'access_token_secret')
consumer_key = config.get('twitter_credentials', 'consumer_key')
consumer_secret = config.get('twitter_credentials', 'consumer_secret')
account_id = config.get('twitter_credentials', 'account_id')
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = API(auth)
msg = "Howdy howdy"
api.update_status(status=msg)
如何获取这个新生成的推文ID?
在官方的tweepy文档中没有关于此的信息。 参考:http://docs.tweepy.org/en/v3.2.0/api.html
答案 0 :(得分:0)
这比你可能想要的更微不足道。
从documentation您可以看到update_status
方法返回status
个对象。和API
中的大多数方法一样。此status
对象基本上包含有关该推文的所有信息。
# after establishing a connection
In [15]: msg = "Tweeting from tweepy"
# retain the object returned
In [16]: tweet = api.update_status(status=msg)
# the id (and practically any attribute, print a tweet to view them!)
# can be easily accessed via
In [17]: tweet.id_str
Out[17]: u'646306396464656384'