好的,我試圖用Google Drive SDK設置我的應用程序。我使用它作爲服務帳戶,所以設置有點不同。這就是我正在做的事情:Google Drive SDK:從generateAssertion()獲取令牌後的下一步
包括所需的文件:
require_once 'google-api-php-client/src/Google_Client.php';
require_once 'google-api-php-client/src/auth/Google_AssertionCredentials.php';
require_once "google-api-php-client/src/contrib/Google_Oauth2Service.php";
定義常量:
DEFINE("TRUE_PATH",$_SERVER["DOCUMENT_ROOT"].'path/to/file');
DEFINE("SERVICE_ACCOUNT_EMAIL","[email protected]");
DEFINE("DRIVE_SCOPE","https://www.googleapis.com/auth/drive");
功能:
function generateAssertion() {
$assertionCredentials = new Google_AssertionCredentials();
$assertionCredentials->serviceAccountName='[email protected]';
$assertionCredentials->privateKey=
TRUE_PATH.'9e01fd1414aa082fadeec316161eb7028558fbde-privatekey.p12';
$assertionCredentials->privateKeyPassword = 'notasecret';
$p12cert = array();
$file = TRUE_PATH.'9e01fd1414aa082fadeec316161eb7028558fbde-privatekey.p12';
if (file_exists($file)) {
try {
$assertion = $assertionCredentials->generateAssertion();
return $assertion;
} catch (Exception $e) {
d($assertionCredentials);
return 'Caught exception: ' . $e->getMessage() . "\n";
}
} else {
return "no p12 privatekey file";
}
}
行$斷言= $ assertionCredentials - > generateAssertion();讓我說,loooks像這樣的代碼:)
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiJodHRwczpcL1wvYWNjb3VudHMuZ29vZ2xlLmNvbVwvb1wvb2F1dGgyXC90b2tlbiIsInNjb3BlIjpudWxsLCJpYXQiOjEzNTMzNjk3NzUsImV4cCI6MTM1MzM3MzM3NSwiaXNzIjoiMjY5Mjg1NDU2NjY0QGRldmVsb3Blci5nc2VydmljZWFjY291bnQuY29tIn0.KMBTsGZkhLhddBFtc0PB1qZgtdQYyirhWtYixCYx1zo5Otv9pCUBfvrCXOg3JzR-mzE6zHuCZdmGOD7w_LRwYHJpoo0rdpxDXLjtNCgFZdu1d21cVAnqTkIhMGvdS_K7JP_KioXyi-nBdvZt9IXKaApIdDKhRp-T5HByIeO2ijU
我的問題是,什麼纔是我的代碼/令牌從generateAssertion(回做,這樣我可以訪問我的驅動器帳戶? 我試圖使用它作爲訪問令牌和刷新令牌沒有成功。
我很抱歉如果這是一個愚蠢的問題,但我是新來的sdk 任何幫助將不勝感激。
謝謝!!!
這就是所有記錄在這裏的方式:https://developers.google.com/drive/service-accounts – Nivco