xdevplatform / Twitter-API-v2-sample-code

Sample code for the Twitter API v2 endpoints
https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api
Apache License 2.0
2.66k stars 984 forks source link

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 #58

Closed yeatfaicheong closed 2 years ago

yeatfaicheong commented 2 years ago

Describe the bug Cannot get rules (HTTP 403): {"client_id":"xxxxx","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":"Standard Basic","reason":"client-not-enrolled","type":"https://api.twitter.com/2/problems/client-forbidden"}

To Reproduce

  1. Create environment variable with Bearer token.
  2. Run the py script.
yeatfaicheong commented 2 years ago

I have found the issue. I got this error because although I had the Twitter developer App, but it was a STANDALONE app without attaching to any projects. So, creating a project first and then link to the app is essential to use Twitter API v2.

brandon-yilmaz commented 2 years ago

Hi! i have the same error, how can i attach an app to a project? thanks

andypiper commented 2 years ago

In the developer dashboard, you should be able to create a Project and add an App. Do you have an approved developer account with access to the dashboard?

mariem-snoussi commented 2 years ago

My app is already attached to a project, any ideas as to why it's happening still ? This is only happening with the TweetCount script but other scripts work just fine.

sriharigr-threado commented 2 years ago

Hello, even we are facing a similar issue but on v2/search/all. We do have a premium subscription for Full Archive.

Rushipatel0995 commented 2 years ago

Hi, I have my app inside a project still facing the same error. Could anyone please help?

sriharigr-threado commented 2 years ago

Hi, I have my app inside a project still facing the same error. Could anyone please help?

Hey, in my case, the reason was Full Archive in v2 is available only Academic Research. You can use 1.1v for Full Archive Search

blhprasanna99 commented 2 years ago

Hey , I have academic access ..... I too got same error.....anyone knows why?

jiarui-liu commented 2 years ago

@blhprasanna99 Hi, did you find where the problem is? I also have academic access and got this problem...

tipu-254 commented 2 years ago

@Jerry-Liu-dot Hi, I have the same problem despite having academic access. Did you find the problem?

blhprasanna99 commented 2 years ago

@blhprasanna99 Hi, did you find where the problem is? I also have academic access and got this problem...

Hello!!.....I checked and got academic access again . I was able to complete the work by following the below code https://github.com/jdfoote/Intro-to-Programming-and-Data-Science/blob/fall2021/extra_topics/twitter_v2_example.ipynb

csalmeida commented 1 year ago

I am having the same issue accessing https://api.twitter.com/2/tweets/search/all.

It seems that Essential Access is not enough and you'll get the following error:

{
    "client_id": "20012345",
    "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": "Standard Basic",
    "reason": "client-not-enrolled",
    "type": "https://api.twitter.com/2/problems/client-forbidden"
}

It seems in my case Extended Access is required to access the endpoint.

andypiper commented 1 year ago

@csalmeida you need Academic access to call the full archive search (/2/tweets/search/all) endpoint.

ajeetlabs commented 1 year ago

@blhprasanna99 Hi, did you find where the problem is? I also have academic access and got this problem...

Hello!!.....I checked and got academic access again . I was able to complete the work by following the below code https://github.com/jdfoote/Intro-to-Programming-and-Data-Science/blob/fall2021/extra_topics/twitter_v2_example.ipynb

@blhprasanna99 hey please tell me how you have solved it.

blhprasanna99 commented 1 year ago

@blhprasanna99 Hi, did you find where the problem is? I also have academic access and got this problem...

Hello!!.....I checked and got academic access again. I was able to complete the work by following the below code https://github.com/jdfoote/Intro-to-Programming-and-Data-Science/blob/fall2021/extra_topics/twitter_v2_example.ipynb

@blhprasanna99 hey please tell me how you have solved it.

@ajeetlabs .. I used the code from the link. Please make sure that you got academic research access. You can retrieve the data using that code if you have correct access. I

rico0610 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Ganymede23 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

rico0610 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Ganymede23 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Sorry to hear that. Yes, in my case if did fix the issue.

rico0610 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Sorry to hear that. Yes, in my case if did fix the issue.

Great to know. Are you using a new account or still using the old plans like Essentials and others?

Ganymede23 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Sorry to hear that. Yes, in my case if did fix the issue.

Great to know. Are you using a new account or still using the old plans like Essentials and others?

I've had my Developer account since mid-2022. I currently have the Free plan. Before that, I also had the most basic plan (Essential). I've never had to send a request for Elevated or Academic access. I did get my App 'banned' a few days ago without explanation (apparently lots of people had that issue last week), so I had to create it again. But that was it.

rico0610 commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Sorry to hear that. Yes, in my case if did fix the issue.

Great to know. Are you using a new account or still using the old plans like Essentials and others?

I've had my Developer account since mid-2022. I currently have the Free plan. Before that, I also had the most basic plan (Essential). I've never had to send a request for Elevated or Academic access. I did get my App 'banned' a few days ago without explanation (apparently lots of people had that issue last week), so I had to create it again. But that was it.

Thank you. I'm experiencing the issue with the new account I've created. My old account with essential plan is working just fine.

Velkonost commented 1 year ago

hello I regenerated too but didn't help

Uncle-Enzo commented 1 year ago

From the python example supplied in this repo:

response = requests.get( "https://api.twitter.com/2/tweets/search/stream/rules", auth=bearer_oauth

Fails...despite the bearer token being valid.

Kellogs commented 1 year ago

Hi

I am facing similar issues.

1) Created a New Account for Free API Access 2) It automatically creates and binds it to a project name (not of my choosing, no option to add/edit existing project but I can see it) e.g. I can see at the top "Default project-165131599485..." 3) Can post a Tweet with no issue, so my keys are clearly working (using Tweepy 'response = client.create_tweet(text=tweet_text)' 4) however if I try RT a tweet using 'client.retweet(tweetid)' I receive the same message (below)?

"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."

Thank you all

Kellogs commented 1 year ago

Forgot to add, I have regenerated all the keys and it made no difference i.e. cat post a tweet but can't RT a tweet

ricardoborsato commented 1 year ago

I'm also facing this annoying issue. Anyone who actually figured out how to fix could give a light? My app is properly attached to the properly project and tried to regenerate the tokens multiple times.

mumanye commented 1 year ago

Hate to be the bearer of bad news but Elon made the free tier practically useless the only thing you can do is post.

HRK44 commented 1 year ago

I'm using basic tier (paid one) and still facing this issue, any hints on how to fix it? Maybe I'll just contact twitter support

mariuszwieleba-toast commented 1 year ago

I have two apps one is around one year old and one is a new one, for the old one everything works fine but for the new one I have an error: '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.'

Justxd22 commented 1 year ago

i've the same issue new project/app i can't access the api

Justxd22 commented 1 year ago

i've the same issue new project/app i can't access the api

EDIT: making new app fixed it but not all endpoints work :/

rico0610 commented 1 year ago

i've the same issue new project/app i can't access the api

EDIT: making new app fixed it but not all endpoints work :/

Interesting. I did try this before but did not work. Will try it again today and update here

rico0610 commented 1 year ago

Still not working for me. What endpoints are working for you?

Justxd22 commented 1 year ago

@rico0610 /2/users/me the one that worked for me, I'm trying to use the filtered stream endpoint no luck :( and I've deleted my project 3 times I've to wait 24h before creating one again

Justxd22 commented 1 year ago

I think any endpoints that uses bearer_token doesn't work

kylanoneal commented 1 year ago

If your project has "free access" you can only use these endpoints:

Justxd22 commented 1 year ago

@kylanoneal is essential means free access? It says here that stream endpoint works with essential access

Ganymede23 commented 1 year ago

@kylanoneal is essential means free access? It says here that stream endpoint works with essential access

I think that the 'Essential' and 'Elevated' levels of access were discontinued and replaced by Free, Basic and Enterprise. I'm not sure about Academic, though.

Justxd22 commented 1 year ago

Well should stream endpoint work with free access? The docs are outdated

@kylanoneal is essential means free access? It says here that stream endpoint works with essential access

I think that the 'Essential' and 'Elevated' levels of access were discontinued and replaced by Free, Basic and Enterprise. I'm not sure about Academic, though.

kylanoneal commented 1 year ago

Yeah the docs are outdated and confusing. It looks like Filtered Stream API is now only available at enterprise level.

https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level

HRK44 commented 1 year ago

Yeah the docs are outdated and confusing. It looks like Filtered Stream API is now only available at enterprise level.

https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level

Yes I think you're correct, let's fork $42,000/month to get filtered stream.... I guess it's time to scrap twitter

al2m4n commented 1 year ago

Yeah the docs are outdated and confusing. It looks like Filtered Stream API is now only available at enterprise level. https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level

Yes I think you're correct, let's fork $42,000/month to get filtered stream.... I guess it's time to scrap twitter

Is he thinking of covering all SpaceX costs via Twitter? crazy, I'm in with Scrape.

Justxd22 commented 1 year ago

Yeah the docs are outdated and confusing. It looks like Filtered Stream API is now only available at enterprise level. https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-level

Yes I think you're correct, let's fork $42,000/month to get filtered stream.... I guess it's time to scrap twitter

Is he thinking of covering all SpaceX costs via Twitter? crazy, I'm in with Scrape.

Lol, stweet good place to start scrapping but it's limited :/

maymonms commented 1 year ago

Is there any endpoint that works with 'Free access'. Can someone please give the curl command for running it? Since the documentation is out of place, we are not sure which endpoint works.

Justxd22 commented 1 year ago

@rico0610 /2/users/me the one that worked for me, I'm trying to use the filtered stream endpoint no luck :( and I've deleted my project 3 times I've to wait 24h before creating one again

@maymonms

Ganymede23 commented 1 year ago

If your project has "free access" you can only use these endpoints:

* POST /2/tweets

* DELETE /2/tweets/:id

* GET /2/users/me

@maymonms

bsturkar commented 1 year ago

This error is back again. My app is already attached to a project but still throwing this error.

Happened to me to today too. I had to regenerate all my keys and tokens.

Did that resolve the issue on your end? Mine is still has the same error even after deleting the app and project and creating a new one.

Sorry to hear that. Yes, in my case if did fix the issue.

How did you fixed this issue, only creating new project and app worked for you or something else you tried with that.

trimtechnologies commented 1 year ago

Guys, I am faced with this same issue. 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.

I have created a new project and App, yet there is no difference. Please help.

Husseinelghoul commented 1 year ago

Hello @Ganymede23 can you please verify by sharing the source of the endpoints available with free access ?