2017-03-15 66 views
-1

我很新安裝python模塊。我正在嘗試開始使用Tweepy,但我遇到了一個錯誤。語法錯誤驗證tweepy

我已經運行

import tweepy 
auth = tweepy.OAuthHandler(MYCONSUMERKEY, MYCONSUMERSECRET) 

而是返回了以下錯誤:

File "<stdin>", line 1 
    auth = tweepy.OAuthHandler(MYCONSUMERKEY, MYCONSUMERSECRET) 
                  ^
SyntaxError: invalid syntax 

任何想法可能是錯誤怎麼回事?我在OSX上使用Python 2.7埃爾卡皮坦

+0

「^」實際上指向你的錯誤信息的位置?你的格式化全部搞砸了 – Barmar

+0

正好在我的消費者機密的最後一個字符下謝謝! –

回答

0

我認爲你有你的Twitter應用程序的憑據(否則,什麼都不會)。

使用下面的代碼部分(假設你所需要的憑據)

import tweepy 

# Fill this up with the Twitter Apps Credentials (get them @ apps.twitter.com) 
consumer_key = "Your consumer Key" 
consumer_secret = "Your consumer Key Secret" 
access_token = "Your access Token" 
access_token_secret = "Your access Token Secret" 

auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(access_token, access_token_secret) 

api = tweepy.API(auth) 

print "User Name:", api.me().name 
print "Account (@):", api.me().screen_name 

有了這個,你有基本的框架開始使用Tweepy(最後兩行Twitter的API進行交互的基礎上,你的Twitter憑據,應該在Twitter上打印你的名字和@username