2016-04-21 158 views
0

編輯: 複製服務帳戶通過API創建的文件時,副本會經過,但此錯誤仍然存​​在,並且錯誤中的文件ID與副本相對應。當複製文件服務帳戶不擁有(但具有編輯訪問權限)時,副本不會發生,並且錯誤中的文件ID是原始文件。Google Drive API:複製帶有服務帳戶的文件

該服務帳戶在通過API創建的文件之外似乎沒有可見性,並且不具有這些文件副本的可見性。

= - = - = - = - = - = - = - = - = - = - = - = - = -

我收到了同樣的錯誤,因爲這問題:Google Drive API copy() - 404 error,除了我的設置是一個有點不同。

創建文件工作正常。

我正在嘗試通過副本創建文檔,該副本不會被用戶所有,但仍然會給他們讀/寫/無下載訪問權限。如果現在只是複製,我會很高興。

下面是代碼:

$service = GoogleDrive::connect(); 

    $copy = new \Google_Service_Drive_DriveFile(); 
    $copy->setTitle($documentName); 

    try { 
     $createdFile = $service->files->copy($source_id, $copy); 
    } catch (\Exception $e) { 
     print "An error occurred: " . $e->getMessage(); 
    } 

和輸出:

An error occurred: Error calling POST https://www.googleapis.com/drive/v2/files/1RXglHS8P4Klcn28WTsf-QHj9BuBIV0AY3R6PeJitqcM/copy: (404) File not found: 1PKaE72BI0ux3uAv3vCKv4pAT_jsxhJ5uZOY0F1sEcNw 

好像有與目標文件權限的問題?我如何驗證是否有權限或身份驗證問題?我使用OAuth登錄就好了。

下面是客戶端的連接代碼:

static public function connect() 
{ 
    self::$shared_folder = config('google.SharedFolder'); 

    $client_email = config('google.ServiceAccountEmail'); 

    // See if we need to recreate the client 
    if (!GoogleDrive::$client) { 

     $private_key = file_get_contents(config('google.ServiceAccountKeyFile')); 

     GoogleDrive::$client = new \Google_Client(); 

     GoogleDrive::$client->setApplicationName(GoogleDrive::$app_name); 
     $credentials = new \Google_Auth_AssertionCredentials(
      $client_email, 
      GoogleDrive::$scope, 
      $private_key 
     ); 
     GoogleDrive::$client->setAssertionCredentials($credentials); 
    } 

    // Always see if the token is expired 
    if (GoogleDrive::$client->getAuth()->isAccessTokenExpired()) { 
     GoogleDrive::$client->getAuth()->refreshTokenWithAssertion(); 
    } 

    $_SESSION['service_token'] = GoogleDrive::$client->getAccessToken(); 

    return new \Google_Service_Drive(GoogleDrive::$client); 
} 

回答

0

不是一個完整的答案,但我們結束了在域上使用的常規帳戶和存儲他們的標識拷貝文件。我們無法使用服務帳戶驅動器來存儲和複製文件。我們也無法授予用戶對服務帳戶驅動器中的文件的權限。我們甚至嘗試在服務帳戶作爲所有者的情況下在常規用戶的雲端硬盤中創建文檔,但複製和權限失敗。我們能夠使用服務帳戶作爲所有者正確地創建文件,但顯然我們要麼丟失了某些東西,要麼做了不允許的事情。

相關問題