Обновлено:
Мой проект заключается в том, чтобы предоставить веб-приложение, которое позволяет посетителю загружать/загружать/удалять файлы с помощью GoogleDrive. Проект требует, чтобы он был основан на сервере, что не требует учетных данных от пользователя для выполнения этих функций.
Короче говоря, веб-приложение хранит файлы в одной выделенной учетной записи 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 аргумента, однако я не знаю, что это должно быть.
Вот мой код, который я получил по указанному выше 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();
}