Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authenticating error (api_version='2') #226

Closed
965realestate opened this issue Apr 17, 2023 · 8 comments
Closed

Authenticating error (api_version='2') #226

965realestate opened this issue Apr 17, 2023 · 8 comments
Labels

Comments

@965realestate
Copy link

965realestate commented Apr 17, 2023

Is there a problem with authentication requests or I'm doing something wrong?

I tried the Twitters API v2 postman with (OAuth 1.0) Consumer Key, Consumer Secret, Access Token, Token Secret after that creating a tweet with Twitters API v2 it worked perfectly.

code:

# Consumer Keys
consumer_key = ??'
consumer_secret = '??'

# Access Token and Secret
access_token_key = '??'
access_token_secret = '??'

from TwitterAPI import TwitterAPI
api = TwitterAPI(consumer_key, consumer_secret, access_token_key, access_token_secret, api_version='2')

api.request('tweets', {'text': 'testing api'})

response:

Request returned an error: 403 {"client_id":"26924600","detail":"When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.","registration_url":"https://developer.twitter.com/en/docs/projects/overview","title":"Client Forbidden","required_enrollment":"Appropriate Level of API Access","reason":"client-not-enrolled","type":"https://api.twitter.com/2/problems/client-forbidden"}

@geduldig
Copy link
Owner

Looks good to me. Are you using the same credentials with Postman and TwitterAPI?

I would add something to your code to confirm that your credentials are valid.

@965realestate
Copy link
Author

Yes, I'm using the same exact credentials with Postman and TwitterAPI.

What code do I need to add that check my credentials are valid?

@geduldig
Copy link
Owner

You could try other enpoints, such as searching for tweets, that don't require write privileges. I'm really not sure what to tell you. It doesn't make sense that the same credentials would would work in one case and not in the other. Are those credentials associated with a Twitter developer project?

@geduldig
Copy link
Owner

The error you are receiving is from Twitter, so it's impossible to for me to look into the cause. There must be some difference between your requests in Postman and in TwitterAPI. It might be helpful to try the same request using another library such as twarc.

@geduldig
Copy link
Owner

I see one thing you are doing wrong. The 'tweets' request, by default uses HTTP GET. You need to use HTTP POST in order to upload a tweet. Try this...
r = api.request('tweets', {'text':'a test to test'}, method_override='POST')

@965realestate
Copy link
Author

I see one thing you are doing wrong. The 'tweets' request, by default uses HTTP GET. You need to use HTTP POST in order to upload a tweet. Try this... r = api.request('tweets', {'text':'a test to test'}, method_override='POST')

method_override='POST'

Thank you! Problem fixed

@geduldig
Copy link
Owner

geduldig commented Aug 3, 2023 via email

@qkxie
Copy link

qkxie commented Aug 4, 2023

@geduldig

api = TwitterAPI(consumer_key, consumer_secret, access_key, access_secret, api_version='2')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants