I’ve been using Laravel/Socialite to interact with the Twitter API v2 for a while, and everything was working fine until last week. I’m encountering a "403 Forbidden" error with the message:
Client error: `GET https://api.twitter.com/2/users/me?user.fields=profile_image_url` resulted in a `403 Forbidden` {"client_id":"xxxxxxx","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"}
I’m on a free plan, and I’ve confirmed that my Twitter Developer App is associated with a Project. Here are some details about my setup:
Laravel/framework: "^9.19",
Laravel/Socialite version: "^5.5"
Twitter Developer App details: [App Permissions: ‘users.read’, ‘tweet.read’]
Code snippet where the error occurs:
$user = Socialite::driver('twitter-oauth-2')->user();
I’m confused about why this issue suddenly appeared and how to resolve it. Any guidance or insights would be greatly appreciated!
Thank you in advance!
2
Answers
Not sure about the exact cause.
The
user()
callshttps://api.twitter.com/2/users/me
(https://github.com/laravel/socialite/blob/5.x/src/Two/TwitterProvider.php#L57-L65) which is supported by the free plan(https://developer.twitter.com/en/portal/products/free).I tried that api with postman and can confirm that I can get back the user successfully.
I scratched my head for a while about this – even forked repos.
However I think this is about how the
App
is set-up in the X/Twitter developer portal.I think they must have updated the developer portal.
You now need to add a
Project
(you get 1 on the free tier) – when creating theProject
you can add theApp
. Quite sure this has solved the error for my install.