Это мой код для вставки действия:
const SERVICE_ACCOUNT_EMAIL = "xxxxxx";
const KEY_FILE = 'key.p12';
$client_id = 'yyyyyyyyy';
$client_secret = 'zzzzzzzzz';
$redirect_uri = 'ttttttttt';
$client = new Google_Client();
$client->setApplicationName("Prueba_social123");
$key = file_get_contents(KEY_FILE);
$user_credentials = new Google_Auth_AssertionCredentials(
SERVICE_ACCOUNT_EMAIL,
array("https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/plus.stream.write"),
$key);
$user_credentials->sub = "[email protected]";
$client->setAssertionCredentials($user_credentials);
$client->setClientId($client_id);
$client->setClientSecret($client_secret);
$client->setRedirectUri($redirect_uri);
$client->setDeveloperKey('wwwwwwwwwwwwwwwwwwwwww');
$client->setScopes(array('https://www.googleapis.com/auth/userinfo.email', 'https://www.googleapis.com/auth/plus.me', 'https://www.googleapis.com/auth/plus.login', 'https://www.googleapis.com/auth/plus.stream.write') );
$plus = new Google_Service_Plus($client);
$oauth2 = new Google_Service_Oauth2($client);if (isset($_REQUEST['logout'])) {
unset($_SESSION['access_token']);
}if (isset($_GET['code'])) {
$client->authenticate($_GET['code']);
$_SESSION['access_token'] = $client->getAccessToken();
$redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
}if (isset($_SESSION['access_token']) && $_SESSION['access_token']) {
$client->setAccessToken($_SESSION['access_token']);
} else {
$authUrl = $client->createAuthUrl();
}if ($client->getAccessToken()) {
$_SESSION['access_token'] = $client->getAccessToken();
$token_data = $client->verifyIdToken()->getAttributes();
$plusdomains = new Google_Service_PlusDomains($client);
$activityObject = new Google_Service_PlusDomains_ActivityObject();
$activityObject->setOriginalContent("Prueba de actividad desde la API de mensajes123");
$activityAccess = new Google_Service_PlusDomains_Acl();
$activityAccess->setDomainRestricted(true);
$resource = new Google_Service_PlusDomains_PlusDomainsAclentryResource();
$resource->setType("public");
$resources = array();
$resources[] = $resource;
$activityAccess->setItems($resources);
$activity = new Google_Service_PlusDomains_Activity();
$activity->setObject($activityObject);
$activity->setAccess($activityAccess);
$plusdomains->activities->insert("me", $activity);
....................
И я получаю ОШИБКУ:
Неустранимая ошибка: необработанное исключение ‘Google_Service_Exception’ с
сообщение «Ошибка вызова POST
https://www.googleapis.com/plusDomains/v1/people/me/activities?key=xxxxxxxxxxxxxxxx:
(403) Запрещено
/var/www/html/public/pruebas_sociales/google-api/src/Google/Http/REST.php:79
Трассировка стека: # 0
/var/www/html/public/pruebas_sociales/google-api/src/Google/Http/REST.php(44):
Google_Http_REST :: decodeHttpResponse (Object (Google_Http_Request)) # 1
/var/www/html/public/pruebas_sociales/google-api/src/Google/Client.php(512):
Google_Http_REST :: Execute (Object (Google_Client),
Объект (Google_Http_Request)) # 2
/var/www/html/public/pruebas_sociales/google-api/src/Google/Service/Resource.php(195):
Google_Client-> execute (Object (Google_Http_Request)) # 3
/var/www/html/public/pruebas_sociales/google-api/src/Google/Service/PlusDomains.php(491):
Google_Service_Resource-> call (‘insert’, Array, ‘Google_Service _…’)Google_Service_PlusDomains_Activities_ in
/var/www/html/public/pruebas_sociales/google-api/src/Google/Http/REST.php
на линии 79
Я с проблемой две недели назад. Как я могу это исправить? Помогите.
Задача ещё не решена.
Других решений пока нет …