【发布时间】:2014-01-16 21:10:02
【问题描述】:
更新:
我的项目是能够提供一个基于 Web 的应用程序,允许访问者使用 GoogleDrive 上传/下载/删除文件。该项目要求它是基于服务器的,不需要用户的凭据即可执行这些功能。
简而言之,Web 应用程序将文件存储在一个专用的 Google Drive 帐户上,而不是将文件存储在服务器上。
我研究了 Google 的开发者网站,并被指示使用下面的示例作为起点,将 PHP 应用程序配置为使用我设置的 Drive 帐户。
我按照 Google 页面上的说明进行操作: https://code.google.com/p/google-api-php-client/wiki/OAuth2#Service_Accounts
当我执行此脚本时,我收到以下 500 错误:
PHP 可捕获的致命错误:参数 3 传递给 Google_HostedmodelsServiceResource::predict() 必须是 Google_Input,没有给出,调用 /data/sites/scott/htdocs/dfs_development/drive/serviceAccount.php 上 第 62 行并在 /data/sites/scott/htdocs/dfs_development/apis/google-api-php-client/src/contrib/Google_PredictionService.php 第 36 行
我在这里做错了什么?我不确定 $project 变量应该包含什么,并且 predict() 函数似乎需要 3 个 args,但是我不知道它应该是什么。
这是我从上面的 URL 获得的代码。提前感谢您的回复。
require_once '../apis/google-api-php-client/src/Google_Client.php';
require_once '../apis/google-api-php-client/src/contrib/Google_PredictionService.php';
// 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 = 'pathto/secretlystored/######-privatekey.p12';
$client = new Google_Client();
$client->setApplicationName("My Google Drive");
// Set your cached access token. Remember to replace $_SESSION with a
// real database or memcached.
session_start();
if (isset($_SESSION['token'])) {
$client->setAccessToken($_SESSION['token']);
}
// Load the key in PKCS 12 format (you need to download this from the
// Google API Console when the service account was created.
$key = file_get_contents(KEY_FILE);
$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 = 'dfslocalhost';
$predictionData = new Google_InputInput();
$predictionData->setCsvInstance(array('Je suis fatigue'));
$input = new Google_Input();
$input->setInput($predictionData);
$result = $service->hostedmodels->predict($id, $input); ## 500 ERROR occurs here..
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();
}
【问题讨论】:
标签: php google-api-php-client google-prediction