Hi,
Currently I'm developing an application which log in to youtube channel using "https://www.googleapis.com/auth/youtube" scope. I want to get youtube channel ID (not id which it return after log in" so I tried to fetch YouTube Data API and get "mine = true" channel
Here is my code
signIn = async () => {
try{
await GoogleSignin.hasPlayServices({autoResolve: true});
await GoogleSignin.signIn()
.then(res=>{
console.log(res)
fetch("https://www.googleapis.com/youtube/v3/channels?part=snippet,statistic&mine=true&key=[API_KEY]")
.then(res => res.json())
.then(res => {
console.log(res)
})
})
It will return data of the channel user just log in.
It can sign in. The log shows accessToken idToken serverAuthCode and stuffs but...
{
"error": Object {
"code": 401,
"errors": Array [
Object {
"domain": "youtube.parameter",
"location": "mine",
"locationType": "parameter",
"message": "The request uses the <code>mine</code> parameter but is not properly authorized.",
"reason": "authorizationRequired",
},
],
"message": "The request uses the <code>mine</code> parameter but is not properly authorized.",
},
}
I'm not sure about solution but i think in google api have scope of each api please check on (https://developers.google.com/youtube/v3/docs/channels/list ) and inside docs includes oauth 2.0
react-native-google-signin : 1.2.1
GoogleSignin.configure({ scopes: ['https://www.googleapis.com/auth/drive.readonly'], // what API you want to access on behalf });
I hope this helps na.
I did try to add scopes, still doesn't work. :-( Thanks for the help by the way na
@ItsMePol Please try this add bearer token, No idea anymore good luck
try{
await GoogleSignin.hasPlayServices({autoResolve: true});
await GoogleSignin.signIn()
const {accessToken} = await GoogleSingin.getTokens() // i think this can get token
const response = await fetch("https://www.googleapis.com/youtube/v3/channels?part=snippet,statistic&mine=true&key=[API_KEY]",{
" Authorization: Bearer `${accessToken}`"
}) //here just add bearer
}catch(error){
//err
}
I DID IT!
I added
https://www.googleapis.com/youtube/v3/channels?part=snippet,statistic&mine=true&key=[API_KEY]&access_token=[ACCESS TOKEN FROM LOGIN]
Thank you for the idea!
can't get access token on android from getTokens() method
it returns nothing.
Please reply as soon as possible
@Aksh0377 please check about oauth in your import api. Google has many rules about api. I think you should see in youtube api group may help : )
because here is react comunity
Hey @tatatatam
Thanks for your quick response, but here I am talking about the GoogleSignIn.getToken() method of this package.
GoogleSignin.signIn() method works fine. I get user data from it.
but
GoogleSignIn.getToken() returns nothing. it should return the access_token as per the documentation,
found any solutions???
Most helpful comment
I DID IT!
I added
https://www.googleapis.com/youtube/v3/channels?part=snippet,statistic&mine=true&key=[API_KEY]&access_token=[ACCESS TOKEN FROM LOGIN]Thank you for the idea!