lundi 3 juin 2019

How to fetch my own videos after authenticating

I'm using laravel-socialite to authenticate with google driver. Everything goes fine and I get my token needed to make offline requests. I create a new instance of the Google Client and I pass the needed configuration to make it work. Then I create a Google Service Youtube and try to fetch my videos. I fetched some videos but they are not mine (some random videos ordered by popularity in youtube). My question here is what parameters do I need to pass and where to fetch my videos. If I need to get my youtube channel ID, how do I do that?


 if (file_exists(storage_path('app/google.json'))) {
                $userConnection = auth()->user()->connections()->where('name', 'google')->firstOrFail();

                $client = new Google_Client();
                $client->setAuthConfig(storage_path('app/google.json'));
                $client->setAccessType('offline');
                $client->setScopes(Google_Service_Youtube::YOUTUBE_READONLY);
                $client->fetchAccessTokenWithRefreshToken($userConnection->pivot->token);

                $youtubeData = new \Google_Service_YouTube($client);

                $queryParams = [
                    'maxResults' => 25,
                    'chart' => 'mostpopular',
                ];

                $videos = $youtubeData->videos->listVideos('snippet', $queryParams);
                dd($videos);
            } else {
                throw new Exception('Google credentials json file not found');
            }
            dd($videos->getItems());
            return $next($request);
        });




via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire