1
我正在使用django-social-auth和tweepy在Django使用其api發佈推特信息。使用Twitter登錄工作正常,但發佈推文時,我從views.py得到這個錯誤:global name 'oauth_token' is not defined.
在此先感謝。錯誤:未定義全局名稱'oauth_token'
from django.shortcuts import render
from django.contrib.auth import logout
from social_auth.models import UserSocialAuth
import tweepy
from twapp import settings
def index(request):
if request.method == 'POST':
instance = UserSocialAuth.objects.filter(user=request.user).get()
oauth_access_token = (instance.tokens).get(oauth_token)
oauth_access_secret = (instance.tokens).get(oauth_token_secret)
print oauth_access_token
auth = tweepy.OAuthHandler(settings.TWITTER_CONSUMER_KEY, settings.TWITTER_CONSUMER_SECRET)
auth.set_access_token(oauth_access_token, 'oauth_access_secret')
api = tweepy.API(auth)
print api.me().name
api.update_status('Updating using OAuth authentication via Tweepy!')
return render(request, 'home.html')
def logout_view(request):
logout(request)
return render(request, 'home.html')
你確定它不應該是'oauth_access_secret'?否則,發佈一些代碼。 – robertklep 2013-03-21 15:22:56
謝謝@robertklep,編輯問題! – floyddd 2013-03-21 15:42:02
把雙引號'.get('oauth_token')' – catherine 2013-03-21 15:55:40