验证tweepy时出现语法错误

2024-06-28 11:22:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我对在python上安装模块很陌生。我试着开始用Tweepy,但我遇到了一个错误。在

我跑了

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

但返回以下错误:

^{pr2}$

你知道这里会出什么问题吗?我在OSX El Capitan上使用Python2.7


Tags: 模块importauth错误elosxtweepypr2
1条回答
网友
1楼 · 发布于 2024-06-28 11:22:48

我想你有你的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。在

相关问题 更多 >