0

I have an app, using this app in which user can sign-up via twitter and I have set permission of Read, write, and direct messages , So when user sign-up to my project he authorized me that I can post on-behalf of him. Also during signup I have got his oauth-token and oauth-token secret.

But I don't know how I can post tweet on behalf of that user. I try to submit a form at https://api.twitter.com/1.1/statuses/update.json with parmas like status , my app key and secret , user oauth_token and secret but in response I am always getting this

{"errors":[{"message":"Bad Authentication data","code":215}]}

I am using python-social-auth for sign up via twitter.

Any help would be appreciated. Thanks

4

1 回答 1

4

您需要在access_token请求中指定用户,这是 Twitter 知道哪个是当前经过身份验证的用户的方式。与python-social-auth您一起可以:

# given a user instance (and assuming Django ORM)
social = user.social_auth.get(provider='twitter')
backend = social.get_backend()
form_data = {
    'status': 'The new twitter status goes here'
}
response = backend.get_json(
    'https://api.twitter.com/1.1/statuses/update.json', 
    method='POST',
    auth=backend.oauth_auth(social.extra_data['access_token']),
    data=form_data
)
于 2014-03-31T15:16:14.120 回答