Tweepy:带有“错误身份验证数据"错误的简单脚本 [英] Tweepy: simple script with 'Bad Authentication data' error

查看:20
本文介绍了Tweepy:带有“错误身份验证数据"错误的简单脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这真的是身份验证问题还是与其他问题有关?我必须修改什么才能消除错误?

Is this really an authentication problem or has it to do with something else? What do I have to modify to get rid of the error?

#!/usr/bin/env python
import tweepy

ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'

auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

api = tweepy.API(auth)

results = tweepy.api.search(geocode='50,50,5mi')

for result in results:
    print result.text
    print result.location if hasattr(result, 'location') else "Undefined location"

这是我得到的错误

C:\Python27\python.exe C:/untitled/testfile.py
Traceback (most recent call last):
  File "C:/untitled/testfile.py", line 18, in <module>
    results = tweepy.api.search(geocode='50,50,5mi')
  File "build\bdist.win-amd64\egg\tweepy\binder.py", line 197, in _call
  File "build\bdist.win-amd64\egg\tweepy\binder.py", line 173, in execute
tweepy.error.TweepError: [{u'message': u'Bad Authentication data', u'code': 215}]

推荐答案

你做错了:

应该是——

#!/usr/bin/env python
import tweepy

ckey = 'xxx'
csecret = 'xxx'
atoken = 'xxx'
asecret = 'xxx'

auth = tweepy.OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

api = tweepy.API(auth)

# here's where you went wrong (tried and tested), should be
#results = api.search(geocode='50,50,5mi')
# try with the following lat long
results = api.search(geocode='39.833193,-94.862794,5mi') 

for result in results:
    print result.text
    print result.location if hasattr(result, 'location') else "Undefined location"

这篇关于Tweepy:带有“错误身份验证数据"错误的简单脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆