Open
Description
Describe the bug
In the dashboard, there are two endpoints given to getting the followings of an account,
one is by using the user's ID <GET /2/users/:id/following>
and the other is by using the user's name <GET /2/users/by/username/:username/following>
the one with ID works, however, the one with username return 404 in response
To Reproduce
Run this code:
import requests
import json
bearer_token = "{YOUR TOKEN}"
def bearer_oauth(r):
r.headers["Authorization"] = f"Bearer {bearer_token}"
r.headers["User-Agent"] = "v2FullArchiveSearchPython"
return r
def connect_to_endpoint(url, params, method: str = 'GET'):
response = requests.request(method, url, auth=bearer_oauth, params=params)
print(response.status_code)
if response.status_code != 200:
raise Exception(response.status_code, response.text)
return response.json()
def get_acc_followings(user_name: str):
search_url = "https://api.twitter.com/2/users/by/username/%s/following" % user_name
print(search_url)
query_params = {"user.fields": "id,name,public_metrics,username"}
json_response = connect_to_endpoint(search_url, query_params)
print(json.dumps(json_response, indent=4, sort_keys=True))
if __name__ == "__main__":
get_acc_followings('{PUT USERNAME HERE}')
Expected behavior
The response should include details of "following" users
Additional context
Running the same code by using the user's ID works just fine.
def get_acc_followings_by_id(user_id: str):
search_url = "https://api.twitter.com/2/users/%s/following" % user_id
print(search_url)
query_params = {"user.fields": "id,name,public_metrics,username"}
json_response = connect_to_endpoint(search_url, query_params)
print(json.dumps(json_response, indent=4, sort_keys=True))