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

Inforian
  • 1,716
  • 5
  • 21
  • 42
  • Ensure that you're making the request to the API via https:// and not via http://. Also, this might be helpful: http://dev.twitter.com/discussions/15244 – xyres Mar 31 '14 at 08:13

1 Answers1

4

You need to specify the user access_token with your request, that's the way Twitter knows which is the current authenticated user. With python-social-auth you can do:

# 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
)
omab
  • 3,721
  • 19
  • 23
  • Is there any api, which will allow me to post a status by just taking 3 parameters - eg: api.PostStatus(text, screen_name, password) ? – sumanth232 Mar 20 '15 at 04:44