Google Plus API - пост Google Plus. Вставка действий с использованием PHP
Я использую приложение Google API для публикации контента в Google Plus с помощью библиотек Google API.
В соответствии с Google Developer API, я сделал следующие шаги.
1) Загрузил библиотеки API Google со https://github.com/google/google-api-php-client. А потом установил композитор и все было сделано.
После этого в консоли разработчика Google я сделал ниже.
1) Создан проект в консоли разработчика (я не использую электронную почту gmail.com).
2) Включен API домена Google+.
3) ключ API, который я создал.
4) Идентификатор клиента OAuth создан.
5) Создайте ключи служебной учетной записи, загрузите файл json и поместите его в папку *.json.
6) Включены менее безопасные приложения.
И тогда мой код PHP
<?php
require_once 'vendor/autoload.php';
// create the Google client
$client = new Google_Client();
putenv('GOOGLE_APPLICATION_CREDENTIALS=/home/google-plus-api/google-api-php-client/service_account_key.json');
/**
* Set your method for authentication. Depending on the API, This could be
* directly with an access token, API key, or (recommended) using
* Application Default Credentials.
*/
$client->useApplicationDefaultCredentials();
$client->setAuthConfig('/home/google-plus-api/google-api-php-client/service_account_key.json');
$client->setRedirectUri("urn:ietf:wg:oauth:2.0:oob");
$client->addScope(Google_Service_Plus::PLUS_ME);
$authUrl = $client->createAuthUrl();
header("Location: $authUrl");
$plus = new Google_Service_Plus($client);
$plusdomains = new Google_Service_PlusDomains($client);
$postBody = new Google_Service_PlusDomains_Activity();
$postBody['object']['originalContent'] = 'Happy Monday';
$result = $plusdomains->activities->insert('me', $postBody);
$result = $plus->people->get('me');
$response->getBody()->write(var_export($result, true));
?>
Все сделано И когда я запускаю этот код, я получаю ошибку ниже.
PHP Notice: Indirect modification of overloaded element of Google_Service_PlusDomains_Activity has no effect in /home/google-plus-api/google-api-php-client/plus_test_new.php on line 23 PHP Fatal error: Uncaught Google_Service_Exception: { "error": { "errors": [ {
"domain": "global",
"reason": "forbidden",
"message": "Forbidden" } ], "code": 403, "message": "Forbidden" } }
in /home/google-plus-api/google-api-php-client/src/Google/Http/REST.php:118 Stack trace:
#0 /home/google-plus-api/google-api-php-client/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 /home/google-plus-api/google-api-php-client/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 /home/google-plus-api/google-api-php-client/src/Google/Http/REST.php(58): Google_Task_Runner->run()
#3 /home/google-plus-api/google-api-php-client/src/Google/Client.php(788): Google_Http_REST::execute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...', Array)
#4 /home/google-plus-api/google-api-php-client/ in /home/google-plus-api/google-api-php-client/src/Google/Http/REST.php on line 118
Пожалуйста, помогите мне, чтобы кто-нибудь избежал этой ошибки и включил эту кодировку
Спасибо,