Hey,
I’m wondering if it’s possible to fetch any users profile picture by his name without having them log in. I’ve tried and read much but I keep getting 401 responses. Do I really need an OAuth token to fetch simple, public data like a profile picture?
Thanks in advance
Use an App Access Token, AKA “client credentials”
Which is for server to server requests/public data
Thanks for helping me that quickly,
I got an oAuth and make a get request as specified in the docs to the following URL:
“https://api.twitch.tv/helix/users?login=Kozie1337 ”
But my response does not include a data field as expected:
Is my URL correct? I’ve tried using uncapitalized names but it still doesn’t work.
Since the status is 200 the authorization at least isn’t the problem anymore.
Your code didn’t process/spit out the response.
So would need to see your code to help with the issue
I was using node-fetch before and data was undefined, now I switched to axios and it works out of a sudden. Thanks
axios
.get("https://api.twitch.tv/helix/users?login=Kozie1337", {
headers: {
"Client-Id": clientid,
Authorization: "Bearer " + token,
},
})
.then((res) => {
console.log(res.data);
});
I don’t know axious
But I’m gonna guess you need to
axios
.get("https://api.twitch.tv/helix/users?login=Kozie1337", {
headers: {
"Client-Id": clientid,
Authorization: "Bearer " + token,
},
responseType: 'json'
})
.then((res) => {
console.log(res.data);
});
The responseType
will tell axois to expect and handle as JSON
And data
should be the whole response object
Personally I use nodeJS Got myself
With node fetch you probablyt needed to do
fetch(url, {options})
.then(resp => { return resp.json(); })
.then(resp => {
// do stuff with resp as it's the json blob that was returned
});
This example might help,
But it’s front end JS
Or this backend example
} else {
// it"s ok
}
})
.catch(err => {
console.error(err);
twitch.makeClientCred();
});
},
makeClientCred: () => {
got({
url: "https://id.twitch.tv/oauth2/token",
method: "POST",
headers: {
"Accept": "application/json"
},
form: {
client_id: config.client_id,
client_secret: config.client_secret,
grant_type: "client_credentials"
},
Covers how Got works for accessing the body
system
Closed
November 22, 2020, 4:35pm
7
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.