I've purchased the Basic plan for Twitter API v2. I forked Twitter's public workspace on Postman to test out the different endpoints I need for my project. When I tried the
https://api.twitter.com/2/users/by/username/:username
It worked and I get the user id. However when I try other end points like:
https://api.twitter.com/2/users/:id/followers
OR
https://api.twitter.com/2/users/:id/following
I get the following response:
{
"client_id": "27723471",
"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"
}
I have created my app inside a project and you can see the settings in the image below:
I have regenerated the API key, API secret, bearer token, access token and access token secret before and after changing the app settings. I have deleted and recreated it, I have deleted and recreated the project about 10 times now with every permutation but the error doesn't seem to go away. I wrote some code in Tweepy uses the :id/following endpoint and not to my surprise it gives the same error.
Tweepy code:
# Set up Tweepy API client
client = tweepy.Client(bearer_token, api_key, api_secret,
access_token, access_token_secret, wait_on_rate_limit=True)
# Initialize tables for TinyDB
predefined_tweets_table = db.table('predefined_tweets')
liked_tweets_table = db.table('liked_tweets')
commented_tweets_table = db.table('commented_tweets')
MY_HANDLE = "xxxxxx"
MY_ID = xxxxxxx
def get_following():
paginator = tweepy.Paginator(
client.get_users_following, # The method you want to use
MY_ID,
max_results=10, # How many tweets per page
)
for page in paginator:
print("\npage",page)
print("\npage.data",page.data) # The tweets are here
print("\npage.meta",page.meta) # The count etc. are here
print("\npage.includes",page.includes) # The includes are here
time.sleep(15)
What can I try next?
Based on the info here https://twittercommunity.com/t/get-2-users-id-following-is-now-broken/197526
https://api.twitter.com/2/users/:id/followers
https://api.twitter.com/2/users/:id/following
These above endpoints were removed by Twitter on June 26 and ironically enough you can still see them in the official documentation!