0
我試圖上傳文件到驅動器使用服務帳戶。我收到以下錯誤,說明權限不足。谷歌驅動器的多部分上傳返回 - (403)權限不足
錯誤調用POST https://www.googleapis.com/upload/drive/v2/files?uploadType=multipart:這裏(403)沒有足夠的權限」
是我的總的代碼。
$client_id = '69649809374-ib5c5qmr7n34adsfsdfsxxxifss95ue7qouplh7v3r.apps.googleusercontent.com'; //Client ID
$service_account_name = '[email protected]account.com'; //Email Address
$key_file_location = 'secretkey.p12'; //key.p12
echo pageHeader("Service Account Access");
if ($client_id == '269649809374-b5c5qmr7n34aifss95ue7qouplh7v3r.apps.googleusercontent.com'
|| !strlen($service_account_name)
|| !strlen($key_file_location)) {
echo missingServiceAccountDetailsWarning();
}
$client = new Google_Client();
$client->setApplicationName("Client_Library_Examples");
if (isset($_SESSION['service_token']))
{
$client->setAccessToken($_SESSION['service_token']);
}
$key = file_get_contents($key_file_location);
$cred = new Google_Auth_AssertionCredentials(
$service_account_name,
array('https://www.googleapis.com/auth/drive'),
$key);
$client->setAssertionCredentials($cred);
$client->addScope("https://www.googleapis.com/auth/drive");
if ($client->getAuth()->isAccessTokenExpired()) {
$client->getAuth()->refreshTokenWithAssertion($cred);
}
$_SESSION['service_token'] = $client->getAccessToken();
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$parentId='0B7yersFxlKMTR2RsMThQSG1RUVk';
$parent = new Google_Service_Drive_ParentReference();
// create a file
DEFINE("TESTFILE", 'testfile-small.txt');
if (!file_exists(TESTFILE))
{
$fh = fopen(TESTFILE, 'w');
fseek($fh, 1024 * 1024);
fwrite($fh, "this is sekhar", 1);
fclose($fh);
}
$parent->setId($parentId);
$file->setParents(array($parent));
$file->setTitle("I am service Account");
$result = $service->files->insert($file,array('data' => file_get_contents(TESTFILE),
'mimeType' => 'application/octet-stream',
'uploadType' => 'media'));
有沒有我的代碼有問題。
感謝DalmTo,與文件夾的問題,現在我能夠能上傳文件,但我怎麼能訪問它們,當我試圖訪問他們,說其沒有權限,我在哪裏可以更改權限查看它通過公開,以便我可以將它們嵌入我的應用程序 –
這是我認爲的另一個問題。 – DaImTo