2016-10-05 15 views
-2

私はユーチューブの動画のキャプションを取得しようとしていますが、私はREST.phpライン118でこのエラーユーチューブAPIエラーログインに必要なPHP

Google_Service_Exceptionを得た:これは私である必要

ログインコード

function getCaptions($app, $developKey, $OAUTH2_CLIENT_ID, $OAUTH2_CLIENT_SECRET){ 

    $client = new Google_Client(); 
    $client->setApplicationName($app); 
    $client->setDeveloperKey($developKey); 
    $client->setClientId($OAUTH2_CLIENT_ID); 
    $client->setClientSecret($OAUTH2_CLIENT_SECRET); 
    $client->setScopes('https://www.googleapis.com/auth/youtube.force-ssl'); 
    $client->setScopes('https://www.googleapis.com/auth/youtube'); 

    $redirect = filter_var('https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'], 
     FILTER_SANITIZE_URL); 
    $client->setRedirectUri($redirect); 

    // Define an object that will be used to make all API requests. 
    $youtube = new Google_Service_YouTube($client); 

    $captions = $youtube->captions->listCaptions('snippet',$video); 

    if (empty($captions)) { 
     $htmlBody .= "<h3>Can't get video caption tracks.</h3>"; 
    } else { 
     $firstCaptionId = $captions[0]['id']; 
     $this->downloadCaption($youtube, $firstCaptionId, $htmlBody); 
    } 

    return response()->json($searchResponse->items[0]->snippet); 
} 

function downloadCaption(Google_Service_YouTube $youtube, $captionId, &$htmlBody) { 
    // Call the YouTube Data API's captions.download method to download an existing caption. 
    $captionResouce = $youtube->captions->download($captionId, array(
     'tfmt' => "srt", 
     'alt' => "media" 
)); 

$htmlBody .= "<h2>Downloaded caption track</h2><ul>"; 
$htmlBody .= sprintf('<li>%s</li>', 
    $captionResouce); 
$htmlBody .= '</ul>'; 
} 

は私が認証($client->authentication($code);)を行うためのコードが必要であることを知っているが、私はそのコードを取得することができますどこか分かりません。

+0

これで更新しますか? – noogui

答えて

0

を使用すると、OAuthの部分に$client->setAuthConfig($oauth_credentials);があることを確認してください:

$client = new Google_Client(); 
$client->setAuthConfig($oauth_credentials); 
$client->setRedirectUri($redirect_uri); 
$client->addScope("https://www.googleapis.com/auth/drive"); 
$service = new Google_Service_Drive($client); 

これは、GoogleがPHP github samplesに提示され、これを行う方法です。 setAuthConfigは常にPHPサンプルに含まれています。

関連する問題