Серверная служба Google Диска?

Я хочу создать приложение Google Диска для хранения файлов изображений и документов из приложения веб-сайта без необходимости аутентификации посетителя или предоставления разрешения на доступ и т. д. Беспрепятственное использование службы googledrive через интерфейс PHP.

Пользователи будут загружать изображения/документы в веб-форму, а файлы будут храниться на 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

person Scott Fleming    schedule 17.01.2014    source источник
comment
На чей Google Диск будет загружаться приложение — на ваш?   -  person Pekka    schedule 18.01.2014
comment
Я немного запутался. Заходят ли ваши пользователи в настоящее время на ваш PHP-сайт? Если да, то можете ли вы жестко закодировать учетные данные для быстрого запуска API Google Диска и DrEdit, чтобы все пользователи просто использовали это соединение?   -  person MonkeyZeus    schedule 18.01.2014
comment
Да, пользователи будут входить в приложение, но мы хотим использовать одну учетную запись Google Диска для хранения изображений и документов, а не диск пользователя.   -  person Scott Fleming    schedule 18.01.2014
comment
возможен дубликат stackoverflow.com/questions/21189523/ . Вопрос может быть другой, но ответ один и тот же ;-)   -  person pinoyyid    schedule 18.01.2014


Ответы (1)


Я думаю, вам следует рассмотреть возможность использования служебной учетной записи для этого.

https://developers.google.com/drive/web/service-accounts

Используя учетную запись службы, вам не придется беспокоиться о входе людей в систему. Все всегда будет загружаться в одну и ту же учетную запись службы.

person DaImTo    schedule 20.01.2014