So I’ve been searching for solutions for quite a while now. I’m new to api’s and i’m not really sure what i’m doing wrong. I think the solution might be simple, I just don’t know how to fix it
This is the part where I need the auth token
function test(accessToken) {
const url = 'https://api.twitch.tv/helix/search/channels?query=a_seagull';
const options = {
method: "GET",
header: {
'client-id': clientID,
'Authorization ': 'Bearer ' + accessToken
}
};
fetch(url, options)
.then( res => res.json() )
.then( data => {
console.log(data);
}
).catch(error=>console.log(error));
}
admin: fixed formatting
Did you generate an access token to use?
Authentication
Given you are using fetch
this suggests front end code, so you’d be looking at logging a user in via implicit auth
yes I already have an access token also I’m just trying to learn how to use web api’s atm so using this in front-end code is okay for now
If you are using a users token that is fine!
Anything else is a violation of the developer agreement.
Just spotted the error in your code:
'Authorization ': 'Bearer ' + accessToken
should be
'Authorization': 'Bearer ' + accessToken
you had an extra space after authoziation
ohh sorry I forgot to remove that space, I was trying to place spaces everywhere when I found a similar post who forgot to place a space after Bearer
but yea I already tried
'Authorization': 'Bearer ' + accessToken
and it doesn’t work
So what is the current code and the error that is returned?
My current code is
function test(accessToken) {
const url = 'https://api.twitch.tv/helix/search/channels?query=a_seagull';
const headers = {'client-id' : clientID, 'Authorization': 'Bearer ' + accessToken};
const myHeaders = new Headers(headers);
console.log(myHeaders.get('Authorization'))
const options = {
method: "GET",
header: myHeaders
};
var myRequest = new Request(url,options);
fetch(myRequest)
.then( res => res.json() )
.then( data => {
console.log(data);
}
).catch(error=>console.log(error));
}
The error is still “OAuth token is missing”
What is
var myRequest = new Request(url,options);
?
Dist
October 16, 2020, 3:12pm
9
1nyxxed:
header: myHeaders
You’re missing an s
, it should be headers: myHeaders
.
1nyxxed
October 16, 2020, 3:36pm
10
I read about that here because I thought I maybe doing fetch wrong
1nyxxed
October 16, 2020, 3:37pm
11
For future reference you just need this
if (document.location.hash) {
var parsedHash = new URLSearchParams(window.location.hash.substr(1));
if (parsedHash.get('access_token')) {
var access_token = parsedHash.get('access_token');
document.getElementById('access_token').textContent = 'Your Access Key from the #url: ' + access_token;
document.getElementById('user_data').textContent = 'Loading';
// call API
fetch(
'https://api.twitch.tv/helix/users',
{
"headers": {
"Client-ID": client_id,
"Authorization": "Bearer " + access_token
}
}
)
.then(resp => resp.json())
.then(resp => {
For example
1 Like
is this coding or something.
system
Closed
November 18, 2020, 9:22pm
14
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.