开发者

Tweepy and SocialRegistration troubles

开发者 https://www.devze.com 2023-02-14 12:16 出处:网络
I\'ve successfully installed Tweepy. I\'ve successfully installed SocialR开发者_高级运维egistration (Twitter oauth). But now i\'m trying to do things in Tweepy that require authentication and it\'s no

I've successfully installed Tweepy. I've successfully installed SocialR开发者_高级运维egistration (Twitter oauth). But now i'm trying to do things in Tweepy that require authentication and it's not working corrrectly. I keep getting the "authentication required" error page. How can I "connect" SocialRegistration w/ Tweepy? Do I need to pass over tokens to tweepy? Can someone who has used both of these modules please help? Thanks in advance.


It's not really clear what you are trying to achieve with the two modules (social-registration and tweepy)

I'm assuming that you are trying to use tweepy API to do something that requires authentication (eg status updates), so here's how to do an simple oauth authentication in tweepy.

#Requirements:
#tweepy
#consumer_key
#consumer_secret
#access_token_key
#access_token_secret

import tweepy

#build auth handler
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token_key, access_token_secret)

# initialize tweepy API
api = tweepy.API(auth)

# thats it. you can start doing stuff that requires authentication =)
api.update_status('tweepy + oauth!')

Anywho, I hope that helps you with whatever you are trying to achieve? If anything, tweepy has great documentation over at http://joshthecoder.github.com/tweepy/docs/index.html (Trust me, its easy to read)

Cheers


I have been using the following code in order to access Twitter API with Tweepy and django-socialregistration:

OAUTH_TOKEN_SECRET = request.session['oauth_api.twitter.com_access_token']['oauth_token_secret']
OAUTH_TOKEN = request.session['oauth_api.twitter.com_access_token']['oauth_token']

CONSUMER_KEY = settings.TWITTER_CONSUMER_KEY
CONSUMER_SECRET = settings.TWITTER_CONSUMER_SECRET_KEY

auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET)

auth.set_access_token(OAUTH_TOKEN, OAUTH_TOKEN_SECRET)

api = tweepy.API(auth)

# Get user's info
user_info = api.me()
0

精彩评论

暂无评论...
验证码 换一张
取 消