I want to see if any of a couple streamers are on then launch their pages. I am working in python and have had a horrible time trying to figure this out. I have my client ID, but there seems to be no documentation on how to request the data through a python call.
The documentation
Tells you how/what format to make the call.
It provides no opinion on what curl library you should use in any language. Most people will use the existing library they already use for other API’s/general use.
The page
Suggests three different possible HTTP Libraries
Just a clarification, user_id is just twitch username correct?
edit: What is the difference between user_login and user_id
edit pt.2: Frustrated again getting error 404 not found with following code:
import requests
API_ENDPOINT = ‘https://api.twitch.tv/helix/streams?user_id=scarra’
Client_ID = ‘my id removed here’
#data to be sent ot api
data = {
‘Cleint-ID’ : Client_ID
}
r = requests.post(url = API_ENDPOINT, data = data)
print(r.text)
No, user_id
is the users ID on Twitch, not their username. If you look at the example response in the docs there are 2 fields "user_id": "23161357", "user_name": "LIRIK",
, The first is that users ID, the second is their username (which would be the user_login
parameter when making a request).
As for the reason you’re getting a 404 error, that’s because your sending a POST request, where as this endpoint uses a GET request as specified in the docs. You would also need to change ?user_id=scarra
to ?user_login=scarra
as you’re trying to make a request by username, rather than ID.
Thanks so much! Got to the next error! It says to provide a valid Client_ID Which it should according to the above code correct?
Sorry for being a noob, again, thanks!
I’m not a Python dev, but it looks like you’re sending the Client-ID in the request body. You need to send it as a header.
Changed data to headers. As you can see above I just misspelled Client-ID like a true Pepega. Posting my code below to help anyone else who wants to see how to do this in python. Again thank you so much to everyone who helped!!!
import requests
API_ENDPOINT = ‘https://api.twitch.tv/helix/streams?user_login=Channel_Name_Here’
#example Client_ID put yours here
Client_ID = ‘z3n1vw72139876szfjjd5xqs527n0u’
#data to be sent to api
head = {
‘Client-ID’ : Client_ID
}
#api call here
r = requests.get(url = API_ENDPOINT, headers = head)
#data output
print(r.text)
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.