使用" python-social-auth"发布推文

时间:2015-06-22 07:15:56

标签: python django twitter social python-social-auth

我使用python-social-auth将twitter与帐户关联Django,我需要从python发布推文,这是我的代码:

social = user.social_auth.get(provider='twitter')
backend = social.get_backend()
data = {'status': 'Hello'}
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=data
)

结果是这个错误: TypeError:unbound方法oauth_auth()必须使用TwitterOAuth实例作为第一个参数调用(得到dict实例inst) EAD)

然后使用:

backend = social.get_backend_instance()

但是,结果是:

AttributeError: 'NoneType' object has no attribute 'find'

python-social-auth的版本:

python-social-auth == 0.2.10和Django == 1.8.2

回溯:

Traceback (most recent call last):
  File "<input>", line 4, in <module>
  File "/Users/jrperdomoz/.virtualenvs/venv/lib/python2.7/site-packages/social/backends/oauth.py", line 289, in oauth_auth
    callback_uri=self.get_redirect_uri(state),
  File "/Users/jrperdomoz/.virtualenvs/venv/lib/python2.7/site-packages/social/backends/oauth.py", line 98, in get_redirect_uri
    uri = url_add_parameters(uri, {'redirect_state': state})
  File "/Users/jrperdomoz/.virtualenvs/venv/lib/python2.7/site-packages/social/utils.py", line 68, in url_add_parameters
    fragments = list(urlparse(url))
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py", line 143, in urlparse
    tuple = urlsplit(url, scheme, allow_fragments)
  File "/usr/local/Cellar/python/2.7.10/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urlparse.py", line 182, in urlsplit
    i = url.find(':')
AttributeError: 'NoneType' object has no attribute 'find'

由于

0 个答案:

没有答案