0

I have the following code:

photo = open(os.path.join("images", localFileName), 'rb')
tweetThis = "status"
twitter.update_status_with_media(status=tweetThis, media=photo)

Here is the traceback:

    twitter.update_status_with_media(status=status, media=photo)
  File "/usr/local/lib/python2.7/site-packages/twython/endpoints.py", line 107, in update_status_with_media
    return self.post('statuses/update_with_media', params=params)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 234, in post
    return self.request(endpoint, 'POST', params=params, version=version)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 224, in request
    content = self._request(url, method=method, params=params, api_call=url)
  File "/usr/local/lib/python2.7/site-packages/twython/api.py", line 194, in _request
    retry_after=response.headers.get('retry-after'))
twython.exceptions.TwythonError: Twitter API returned a 403 (Forbidden), Status creation failed: Tweet creation failed.

I have tested twitter.update_status(status='TEST') which works correctly meaning I have the correct credentials and permissions. What's wrong with the media version?

4

1 回答 1

1

尝试更改os.path.join("images", localFileName)为 just /path/to/file。不完全确定,但这是唯一可能出错的事情。另外,不要将您的变量设置为您的状态status,它会影响twython语法:twython.twitter.update_status_with_media(status, media)

这是一个例子:

from twython import Twython
from time import strftime

CONSUMER_KEY = '***'
CONSUMER_SECRET = '***'
ACCESS_KEY = '***'
ACCESS_SECRET = '***'

#load your twitter credentials
twyapi = Twython(CONSUMER_KEY,CONSUMER_SECRET,ACCESS_KEY,ACCESS_SECRET)
photo = open('/Users/aj8uppal/Desktop/images.jpg', 'rb')
twyapi.update_status_with_media(status='I love python!', media=photo)
于 2014-03-02T04:35:34.947 回答