Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Youtube Data Api - Members Endpoint - Access forbidden. The request may not be properly authorized

$
0
0

Description:

I'm encountering an issue while implementing the YouTube Data API in my Node.js backend.

I keep getting the following error:

{"error": {"code": 403,"message": "Access forbidden. The request may not be properly authorized.","errors": [      {"message": "Access forbidden. The request may not be properly authorized.","domain": "youtube.common","reason": "forbidden"      }    ]  }}

I've already set up the OAuth flow, obtained the access token, and ensured the correct scopes. Here are the scopes I've included:

scope: ['email','profile','openid','https://www.googleapis.com/auth/youtube.channel-memberships.creator','https://www.googleapis.com/auth/youtube','https://www.googleapis.com/auth/youtube.readonly','https://www.googleapis.com/auth/youtubepartner','https://www.googleapis.com/auth/youtubepartner-channel-audit',]

Surprisingly, I can successfully send a comment to a YouTube live video using the same process, but when it comes to the Members API, it's not working as expected.

Here's the non-functional code snippet:

async requestMembers({  access,  refresh,}: {  access: string;  refresh: string;}) {  const url = `${'https://youtube.googleapis.com/youtube/v3/'}members?part=snippet`;  fetch(url, {    headers: {      Authorization: `Bearer ${access}`,'Content-Type': 'application/json',    },  })    .then((res) => res.json())    .then((json) => {      console.log(JSON.stringify(json));    });}

And here's the working code snippet for sending comments:

sendComment = (text: string, access_token: string, id: string) => {  const url = `${'https://youtube.googleapis.com/youtube/v3/'}liveChat/messages?part=snippet`;  fetch(url, {    method: 'POST',    body: JSON.stringify({      snippet: {        liveChatId: id,        type: 'textMessageEvent',        textMessageDetails: {          messageText: text,        },      },    }),    headers: {      Authorization: `Bearer ${access_token}`,'Content-Type': 'application/json',    },  })    .then((response) => response.json())    .then((data) => console.log('send comment - ', data));};

I've double-checked the OAuth setup, ensured correct scopes, and compared it with the working comment-sending code, but the Members API request remains unauthorized. Any insights or suggestions on what might be causing this issue would be greatly appreciated. Thank you!


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>