OAuth token is missing can someone help me?

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?

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 :confused:

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);

?

You’re missing an s, it should be headers: myHeaders.

I read about that here because I thought I maybe doing fetch wrong

:man_facepalming: :man_facepalming: :man_facepalming:
omg!! thank you very much, I think it’s working now :grin:

For future reference you just need this

For example

1 Like

is this coding or something.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.