2016-10-05 5 views
-2

나는 YouTube 동영상의 자막을 얻기 위해 노력하고 있어요하지만 난 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); 

이 구글에 의해 PHP github samples에 제시된이 일의 방법입니다. setAuthConfig은 항상 PHP 샘플에 포함되어 있습니다.