2012-07-13 1 views
1

다음은 제 코드입니다. - 모든 인증 매개 변수를 두 번 확인했습니다.Oauth2를 사용하여 tweepy에서 api.update_status 메소드를 사용하는 중 오류가 발생했습니다.

import tweepy 


CONSUMER_KEY ='#Omitted - you should not publish your actual key' 
CONSUMER_SECRET ='#Omitted - you should not publish your actual secret' 
ACCESS_KEY='#Omitted - you should not publish your access key' 
ACCESS_SECRET = '#Omitted - you should not publish your access secret' 

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) 
auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) 
api = tweepy.API(auth) 

api.update_status('Tweeting from command line') 

오류를 follwing을 파이썬 status.py를 실행 한 후 status.py 로 홈 폴더에 파일을 저장 제공 : -

Traceback (most recent call last): 
    File "status.py", line 14, in <module> 
    api.update_status('Tweeting from command line') 
    File "/usr/local/lib/python2.7/dist-packages/tweepy-1.10-py2.7.egg/tweepy/binder.py", line 185, in _call 
    return method.execute() 
    File "/usr/local/lib/python2.7/dist-packages/tweepy-1.10-py2.7.egg/tweepy/binder.py", line 168, in execute 
    raise TweepError(error_msg, resp) 
tweepy.error.TweepError: Could not authenticate with OAuth. 

, 나는 인증 할 수 있어요

답변

0

을 저를 도와주세요 tweepy를 사용하면 코드에 다음과 같은 행을 추가 할 수 있습니다.

import tweepy 
from tweepy import OAuthHandler 

그런 다음 코드 나머지 부분을 계속 진행하십시오. 또한 다음과 같이 당신의 연결을 보여 쉘에 출력하는 코드에 줄을 추가 :

print api.me().name

당신이 위의 볼 라인이 있는지 확인 바로 내가 아래에이 오류가 발생 api = tweepy.API(auth)

+0

내가 유 말했다 라인을 추가 ... 여기 코드는 지금과 같은 모습입니다 : - tweepy 수입 OAuthHandler에서 수입 tweepy CONSUMER_KEY = '#의' CONSUMER_SECRET = '#' ACCESS_KEY = '#' ACCESS_SECRET = '#' 인증 = tweepy.OAuthHandler (CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token (ACCESS_KEY, ACCESS_SECRET) API = tweepy.API (인증) 인쇄 api.me(). api.update_status 이름 ('Tweeting from command line') – Divyanshu

+0

여기에 오류가 있습니다 : -, 역 추적 (마지막으로 가장 최근에 호출). 파일 "newstatus.py", 라인 (13), 인쇄 api.me에서() 파일의 이름을 "/usr/local/lib/python2.7/dist-packages/ tweepy-1.10-py2.7.egg/tweepy/api.py ", 182 행, 내 안에 return self.get_user (screen_name = self.auth.get_username()) 파일"/ usr/local/lib/python2. 7/dist-packages/tweepy-1.10-py2.7.egg/tweepy/auth.py ", 줄 161, get_username에서 올리기 TweepError ("사용자 이름을 가져올 수 없습니다. oauth 토큰이 없습니다! ") tweepy.error.TweepError : 사용자 이름, 잘못된 oauth 토큰을 가져올 수 없습니다! – Divyanshu

+0

Tweepy가 oAuth 토큰을 얻는 데 어려움을 겪고있는 것처럼 보입니다. dev.twitter.com 로그인을 확인하고 모든 것이 정확해야합니다. 코드를 복사하여 붙여 넣기 만하면됩니다. 또한 원래의 질문을 수정하기 위해 나중에 확인해보십시오. 이렇게하면 응답 할 때 문자 제한이 없습니다. –

2

후 같은 조건 - tweepy를 사용하면 내 키/비밀 키 모두가 올바르게 복사되고 붙여 넣어집니다. 문제는 내 서버의 시간이었습니다. ntpdate -b pool.ntp.org를 달리고 난 후에 나는 tweepy를 단지 사용하기 위해 있었다.

0

시도 api.update_status(status='Tweeting from command line'). 그것은 나를 도왔다.

관련 문제