2017-02-22 206 views
1

我嘗試使用下面的PHP代碼上傳與谷歌德雲端硬盤API文件上傳問題:PHP與谷歌雲端硬盤API

<?php 

require_once 'src/Google/Client.php'; 
require_once 'src/contrib/Google_DriveService.php'; 
require_once __DIR__.'/vendor/autoload.php'; 


$client_id = 'YOUR CLIENT ID'; 
$client_secret = 'YOUR CLIENT SECRET'; 
$redirect_uri = 'http://localhost/modeloImpacto.php'; 
$client = new Google_Client(); 
$client->setClientId($client_id); 
$client->setClientSecret($client_secret); 
$client->setRedirectUri($redirect_uri); 
//$client->addScope("https://www.googleapis.com/auth/drive"); 
$client->setScopes(array('https://www.googleapis.com/auth/drive')); 
$service = new Google_Service_Drive($client); 

$fileMetadata = new Google_Service_Drive_DriveFile(array(
'name' => 'funcionou.jpg')); 
$content = file_get_contents('funcionou.jpg'); 
$file = $driveService->files->create($fileMetadata, array(
    'data' => $content, 
    'mimeType' => 'image/jpeg', 
    'uploadType' => 'multipart', 
    'fields' => 'id')); 
printf("File ID: %s\n", $file->id); 

?> 

但我遇到以下錯誤:

Fatal error: Class 'Google_ServiceResource' not found in C:\wamp64\www\src\contrib\Google_DriveService.php on line 25 

有人知道我做錯了什麼?

謝謝! Raffael Siqueira。

回答

0

嘗試以下的PHP Quickstart步驟:

  • Step 1: Turn on the Drive API
  • Step 2: Install the Google Client Library
  • Step 3: Set up the sample
  • Step 4: Run the sample

而且,這是很好的檢查Google API Client Upgrade Guide是否有可能會影響您的應用程序的任何更新。

希望這會有所幫助。

相關問題