I'm trying to get all channels and eventually all videos for the user logged into my site with Google. I'm using Laravel Socialite to set the scope that I think should give the proper permissions. I'm then setting the access token to the session.
public function loginGoogle()
{
return Socialite::driver('google')->setScopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
}
When handling the call back after authenticating the user and saving the access token I run the following:
dd(\Youtube::getService()->channels->listChannels('snippet', ['managedByMe' => true, 'onBehalfOfContentOwner' => session('access_token')]));
\Youtube
is just the facade I made to handle Youtube functionality in my site.
When running the code the following error is thrown:
Client error: `GET https://www.googleapis.com/plus/v1/people/me?prettyPrint=false` resulted in a `403 Forbidden` response:
{"error":{"errors":[{"domain":"global","reason":"insufficientPermissions","message":"Insufficient Permission"}],"code":4 (truncated...)
I can't tell if I'm using the incorrect scope or just messing something bigger up. Youtube's documentation hasn't been very helpful in this. They just say the user has to be authorized which...they are?
Been a couple days on this and am not sure where to go next.
Changing
return Socialite::driver('google')->setScopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
to
return Socialite::driver('google')->scopes(['https://www.googleapis.com/auth/youtube.readonly',])->redirect();
seemed to fix it. Looking at the documentation it makes sense why that wouldn't work.