skip to Main Content

I have a simple Python app with Tweepy to upload image to Twitter.
This feature is available only with V1 API.
The access to V1 API is possible either with Standalone App or with Elevated Privileges.

I did both of them but I constantly receive 403 Forbidden error.

Here is my simple code:

client_v1 = tweepy.API(auth=auth)
upload_file_media = client_v1.media_upload(
    filename="my_image.jpg"
)

This, I tried with all 3 possible authentication methods:

auth = tweepy.OAuth2AppHandler
auth = tweepy.OAuth2BearerHandler
auth = tweepy.OAuth1UserHandler

None of them worked.

Here is the stacktrace:

  File "/opt/anaconda3/envs/tf/lib/python3.7/site-packages/tweepy/api.py", line 3411, in media_upload
    additional_owners=additional_owners, **kwargs
  File "/opt/anaconda3/envs/tf/lib/python3.7/site-packages/tweepy/api.py", line 46, in wrapper
    return method(*args, **kwargs)
  File "/opt/anaconda3/envs/tf/lib/python3.7/site-packages/tweepy/api.py", line 3455, in simple_upload
    upload_api=True, **kwargs
  File "/opt/anaconda3/envs/tf/lib/python3.7/site-packages/tweepy/api.py", line 259, in request
    raise Forbidden(resp)
tweepy.errors.Forbidden: 403 Forbidden

Any idea what could be the reason?

Thanks a lot.

2

Answers


  1. Chosen as BEST ANSWER

    I think I found a way of doing this. There is a setting "User authentication settings". Go there and activate Oauthv1. It is asking some callback URL and website URL. If you have commandline or batch job, these are unnecessary. Simply use 127.0.0.1 and localhost. Then it works. weird setting.


  2. If you have a new developer account then you will need Elevated access to access the v1.1 API. You will need to Use the OAuth1UserHandler with the v1.1 media upload API in order to upload media for an authorised user.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search