floyddd
floyddd

Reputation: 81

Error:global name 'oauth_token' is not defined

I am using django-social-auth and tweepy in Django to post tweet to Twitter using its api. Login using Twitter works fine but while posting tweet i get this error from views.py : global name 'oauth_token' is not defined. Thanks in advance.

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')

Upvotes: 1

Views: 2286

Answers (1)

catherine
catherine

Reputation: 22808

Forgot the double quote

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

Upvotes: 1

Related Questions