列出Youtube频道

时间:2017-04-03 13:00:47

标签: php youtube-data-api laravel-5.4

我正在使用Youtube Data API列出经过身份验证的用户频道列表。身份验证是完美的,但是当我想访问频道时,它不会列出它。 结果:

enter image description here

public function getChannels(Request $request)
{
    $client = new Google_Client();
    $client->setClientId(env('GOOGLE_CLIENT_ID'));
    $client->setClientSecret(env('GOOGLE_CLIENT_SECRET'));
    $client->setDeveloperKey(env('GOOGLE_API_KEY'));
    $client->setScopes([
        'https://www.googleapis.com/auth/youtube'
    ]);
    $client->setRedirectUri(env('GOOGLE_REDIRECT'));

    $youtube = new Google_Service_YouTube($client);

    $token = $client->prepareScopes();
    if ($request->has('code')) {
        try{
            $client->authenticate($request->get('code'));
        }catch (\Exception $ex) {
            dd($ex);
        }
        Session::put($token, $client->getAccessToken());
    }
    if (Session::has($token)) {
        $client->setAccessToken($token);
    }
    if($client->getAccessToken()) {
        try {
            dd($youtube->channels);
            $channels = $youtube->channels->listChannels('contentDetails', array('mine' => 'true'));
            dd($channels);
        } catch (\Google_Service_Exception $gSEx) {
            dd($gSEx->getMessage());
        } catch (\Google_Exception $gEx) {
            dd($gEx->getMessage());
        }
        dd($channels);
    }
}

0 个答案:

没有答案