【问题标题】:Error:global name 'oauth_token' is not defined错误:未定义全局名称“oauth_token”
【发布时间】:2013-03-21 15:14:11
【问题描述】:

我在 Django 中使用 django-social-authtweepy 使用其 API 将推文发布到 Twitter。使用 Twitter 登录可以正常工作,但在发布推文时,我从 views.py 收到此错误:global name 'oauth_token' is not defined.提前致谢。

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,问题已编辑!
  • 放双引号.get('oauth_token')
  • oauth_token 传递时没有任何价值

标签: python django twitter


【解决方案1】:

忘记了双引号

oauth_access_token = (instance.tokens).get('oauth_token')

【讨论】:

    猜你喜欢
    • 2013-07-03
    • 1970-01-01
    • 2019-09-09
    • 1970-01-01
    • 2013-06-07
    • 2014-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多