API를

2017-11-27 6 views
0
를 사용하여 Google 드라이브 비디오 소스 코드를 가져옵니다

안녕하십니까,API를

내가 웹 페이지에서 드라이브 내 구글에서 특별히 비디오를 표시 할 필요가 프로젝트를 진행했다. 수동으로 동영상을 선택하고 퍼가기 코드를 복사하고 싶지는 않지만 Google API (PHP 기본 설정)를 사용하여 동영상에 퍼가기 코드를 가져올 수있는 방법이 있습니까?

iframe 내에서이 코드를 사용하고 비디오를 표시 할 수 있도록.

다른 방법이 있는지 제안하십시오. 당신은 구글 드라이브 API https://developers.google.com/drive/v3/web/quickstart/php 그리고 난 당신을 도울 수 있기를 바랍니다 코드의이 세그먼트를 시작할 수

답변

0

사전에

감사합니다. $service->files->listFiles($optParams)Google_Service_Drive_DriveFile 객체 이들 각각은 일련의 속성을 가지고로부터

<?php 
// New Google Client, see all settings at link in description 
$client = new Google_Client(); 

// New Google Drive Service 
$service = new Google_Service_Drive($client); 

// Params with filter of MIME type for search only videos mp4 (you can change this) 
$optParams = [ 
    'q' => "mimeType='video/mp4'", 
    'pageSize' => 10, 
    'fields' => 'nextPageToken, files(id, name, webViewLink)' 
]; 

// Get files from our request 
$files = $service->files->listFiles($optParams); 

// Print an iframe for each video 
foreach($files->files as $file){ 
    // Now I need to make a little detail about the next lines of code so look at [Info] 
    $src = str_replace('/view', '/preview', $file->webViewLink); 
    echo '<iframe width="500" height="200" target="_parent" src="'. $src .'"></iframe>' 
} 
?> 

[정보]

객체는 반환. Google API의 v3에서 embedLink이라는 속성이 제거되었으며 v2 (Migrate to Google Drive API v3)의이 속성에 대한 대체 방법이 없습니다. 내 코드에서 본 것처럼 파일보기에 URL을 반환하는 webViewLink 속성을 사용했습니다 :

https://drive.google.com/file/d/123456789/view 

하지만 당신에 <iframe> 내부 오류 브라우저 통지를이 URL을 사용하는 경우 :

Refused to display 'https://drive.google.com/file/d/123456789/view' in a frame because it set 'X-Frame-Options' to 'sameorigin'.` 

나는이 문제에 너무 많이 들고 아니에요을하고 이것에 대해 lot of question이 있습니다. 그래서 우리는 파일의 미리보기가 아닌보기를 요청해야하는 I는 할 요청에 의해 반환 된 URL에와

str_replace('/view', '/preview', $file->webViewLink);

그. 이제이 URL을

+0

@alvarofvr에 보내 주셔서 감사합니다. 정말 고맙습니다. 내 코드는 $ files의 모든 응답을 인쇄 할 수있는 방법과 조금 다릅니다. 놀랍게도 embedlink가 정확하게 필요한 결과 중 하나였습니다. –