有人可以告诉我为什么这不会在我的Twitter帐户中发布状态?我一直在尝试做一个uni项目,我从Python发布到twitter,但我无法使用基础知识。
import tweepy
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
post = ("testing")
#consumer key, consumer secret, access token, access secret.
ckey="xxxxxxxxxxxxxx"
csecret="xxxxxxxxxxxxx"
atoken="xxxxxxxxxxxxxx"
asecret="xxxxxxxxxxxxxx"
class listener(StreamListener):
def on_data(self, data):
#print(data)
return(True)
def on_error(self, status):
print status
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
api = tweepy.API(auth)
api.update_status('hey, im posting this using python')
答案 0 :(得分:0)
似乎一切都好!
您使用的是哪个版本的tweepy?这段代码适合我:
import tweepy2
#Consumer keys and access tokens
consumer_key = 'X'
consumer_secret = 'X'
access_token = 'X'
access_token_secret = 'X'
# OAuth process
auth = tweepy2.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
# Creation of the actual interface
api = tweepy2.API(auth)
# Post status
api.update_status('Good morning from stackOverflow :)!')
我使用tweepy2(https://bitbucket.org/sakito/tweepy)允许您使用私有代理,但无论如何,只需将tweepy2更改为tweepy(如果您正在使用此代理http://www.tweepy.org/ })它应该工作:)