0
我期待構建一個Google Drive應用程序,以存儲來自網站應用程序的圖像和文檔文件,而不需要訪問者身份驗證或提供訪問權限等。無縫使用通過PHP界面的googledrive服務。基於服務器的Google雲端硬盤服務?
用戶將圖片/文檔上傳到網絡表單,這些文件存儲在GoogleDrive而不是本地文件系統中。
我只是需要幫助,因爲我所使用的所有Google客戶端示例都需要基於用戶的授權和權限。
我的代碼現在似乎把我的Google_DriveService陣列:
require_once '../apis/google-api-php-client/src/Google_Client.php';
require_once '../apis/google-api-php-client/src/contrib/Google_PredictionService.php';
require '../apis/google-api-php-client/src/contrib/Google_DriveService.php';
session_start();
// Set your client id, service account name, and the path to your private key.
// For more information about obtaining these keys, visit:
// https://developers.google.com/console/help/#service_accounts
const CLIENT_ID = '########.apps.googleusercontent.com';
const SERVICE_ACCOUNT_NAME = '#########@developer.gserviceaccount.com';
// Make sure you keep your key.p12 file in a secure location, and isn't
// readable by others.
const KEY_FILE = '##########-privatekey.p12';
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$client = new Google_Client();
$key = file_get_contents(KEY_FILE);
$client->setClientId(CLIENT_ID);
$client->setAssertionCredentials(new Google_AssertionCredentials(
SERVICE_ACCOUNT_NAME,
array('https://www.googleapis.com/auth/prediction'),$key));
$client->setClientId(CLIENT_ID);
$service = new Google_PredictionService($client);
// Prediction logic:
$id = '9146497114232; # replaced with random numbers for this post
$hostedModelName= 'sample.languageid';
$predictionData = new Google_InputInput();
$predictionData->setCsvInstance(array('Foo Bar A Doo')); ## Not sure what this is or what I need here?
$input = new Google_Input();
$input->setInput($predictionData);
$result = $service->hostedmodels->predict($id,$hostedModelName, $input);
# print '<h2>Prediction Result:</h2><pre>' . print_r($result, true) . '</pre>';
// We're not done yet. Remember to update the cached access token.
// Remember to replace $_SESSION with a real database or memcached.
if ($client->getAccessToken()) {
$_SESSION['token'] = $client->getAccessToken();
}
$driveService = new Google_DriveService($client);
print_r($driveService);
exit;
我返回的對象冗長的陣列,並從那裏,我寧願石牆。
其中一些看起來像:
[service:Google_ServiceResource:private] => Google_DriveService Object
*RECURSION*
[serviceName:Google_ServiceResource:private] => drive
[resourceName:Google_ServiceResource:private] => revisions
[methods:Google_ServiceResource:private] => Array
(
[delete] => Array
(
[id] => drive.revisions.delete
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => DELETE
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
[get] => Array
(
[id] => drive.revisions.get
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => GET
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
[2] => https://www.googleapis.com/auth/drive.metadata.readonly
[3] => https://www.googleapis.com/auth/drive.readonly
)
)
[list] => Array
(
[id] => drive.revisions.list
[path] => files/{fileId}/revisions
[httpMethod] => GET
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[response] => Array
(
[$ref] => RevisionList
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
[2] => https://www.googleapis.com/auth/drive.metadata.readonly
[3] => https://www.googleapis.com/auth/drive.readonly
)
)
[patch] => Array
(
[id] => drive.revisions.patch
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => PATCH
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[request] => Array
(
[$ref] => Revision
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
[update] => Array
(
[id] => drive.revisions.update
[path] => files/{fileId}/revisions/{revisionId}
[httpMethod] => PUT
[parameters] => Array
(
[fileId] => Array
(
[type] => string
[required] => 1
[location] => path
)
[revisionId] => Array
(
[type] => string
[required] => 1
[location] => path
)
)
[request] => Array
(
[$ref] => Revision
)
[response] => Array
(
[$ref] => Revision
)
[scopes] => Array
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.file
)
)
)
)
[version] => v2
[servicePath] => drive/v2/
[resource] =>
[serviceName] => drive
這個應用程序會將Google雲端硬盤的上傳內容轉發給您的朋友嗎? –
我有點困惑。你的用戶目前是否登錄到你的PHP站點?如果是這樣,那麼您是否可以對[Google Drive API快速入門](https://developers.google.com/drive/quickstart-php)和[DrEdit](https://developers.google.com/)的憑據進行硬編碼驅動器/例子/ PHP),以便所有用戶只使用該連接? – MonkeyZeus
是的,用戶將登錄到應用程序,但我們希望使用一個Google Drive帳戶存儲圖像和文檔,而不是用戶的驅動器。 –