【问题标题】:Tweet on behalf of users who have authenticated my app to post tweet?代表已对我的应用进行身份验证的用户发布推文?
【发布时间】:2014-05-10 08:14:35
【问题描述】:

我有一个应用程序,使用这个应用程序,用户可以sign-up via twitter,并且我设置了读取、写入和直接消息的权限,所以当用户注册我的项目时,他授权了我可以代表他发帖。同样在注册期间,我得到了他的 oauth-token and oauth-token secret

但我不知道如何代表该用户发布推文。我尝试在https://api.twitter.com/1.1/statuses/update.json 提交一个表单,其中包含状态、我的应用程序密钥和秘密、用户 oauth_token 和秘密等参数,但作为回应,我总是得到这个

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

我正在使用 python-social-auth 通过 twitter 进行注册。

任何帮助将不胜感激。 谢谢

【问题讨论】:

标签: python django twitter python-social-auth


【解决方案1】:

您需要在请求中指定用户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
)

【讨论】:

  • 是否有任何 api,它可以让我通过 3 个参数来发布状态 - 例如:api.PostStatus(text, screen_name, password)?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-05-20
  • 2015-05-01
  • 2018-05-10
  • 2021-10-26
  • 1970-01-01
  • 2010-11-29
  • 1970-01-01
相关资源
最近更新 更多