Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP - Getting Channel ID after OAuth - YouTube API

Firstly, this question may sound like a duplicate but from the answers I've already seen I think the answers don't correctly fit this purpose because I do not have permission.

I'm trying to find a YouTube channel ID after they authorize their Google account.

The scopes I am using are:

https://www.googleapis.com/auth/yt-analytics.readonly
https://www.googleapis.com/auth/userinfo.profile

A lot of the answers refer to accessing the V3 channels api to get the channel id.

$channelData = file_get_contents("https://www.googleapis.com/youtube/v3/channels?part=id&mine=true&access_token=".$token['access']);
$channelData = json_decode($channelData, true);

The issue is with the scopes I'm using you cannot access this. The other questions on SO all revolve around this endpoint.

Youtube API Retrieving Channel ID after authentication

How to get Channel ID (YouTube API v2)?

How to Get Channel id or url after Google Oauth PHP

Please note I want to keep scopes to an absolute minimum. Why wouldn't this simply be possible with just the analytics API? Will I have to use another YouTube scope to find the channel id of the person who just authorised?

The question I'm asking is

Is there any way I can get the channel id of the user who just authorised with my current scopes? If not what is the minimum-amount-of-permission-scopes I can use to get their channel id?

like image 238
ConorReidd Avatar asked Aug 24 '17 20:08

ConorReidd


People also ask

How can I get YouTube channel ID in PHP?

Get the YouTube channel ID To obtain the channel id you can view the source code of channel page and find there data-channel-external-id="XXXXXXXXXXXXXXXXXXXXXXXX" this will be the channel id you are looking for!


1 Answers

You should add youtube.readonly scope, plugins like socialite have exactly this scope hardcoded. The channel snippet can be got via channels method - docs with part=snippet.

Readonly scope is light enough to include it to your list. userinfo.profile and yt-analytics.readonly don't have access to channels list. This scope is the only one needed to get channel id.

like image 89
shukshin.ivan Avatar answered Oct 04 '22 01:10

shukshin.ivan