I am trying to fetch Twitch's user ID through their API, but I am not being able to do so. This is my first time using APIs.
Right now this is my code:
import requests
import json
parameters = {
"login": "shroud,impakt"
}
response = requests.get("https://api.twitch.tv/kraken/users/", params=parameters, headers={'Accept': 'application/vnd.twitchtv.v5+json', 'Client-ID': 'xytnh8lrt9k8l4lpv22gogmdnfp1bg'})
userid = response.json()["users"][0]["_id"]
ids = []
for d in userid:
uid = d["_id"]
ids.append(uid)
print(ids)
I believe I may need to use a for loop, but am not understanding how to approach this.
Here is an example of the data response:
{
"_total": 1,
"users": [
{
"display_name": "shroud",
"_id": "37402112",
"name": "shroud",
"type": "user",
"bio": "I'm back baby",
"created_at": "2012-11-03T15:50:32.87847Z",
"updated_at": "2021-06-18T15:48:05.411438Z",
"logo": "https://static-cdn.jtvnw.net/jtv_user_pictures/7ed5e0c6-0191-4eef-8328-4af6e4ea5318-profile_image-300x300.png"
}
]
}
When running I get the error TypeError: string indices must be integers
.