Trying to find how to post to google plus wall from PHP but got 403 even using the api explorer at got the
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
My PHP code looks like:
$client = new Google_Client();
$client->setApplicationName("Speerit");
$client->setClientId($appId);
$client->setClientSecret($appSecret);
$client->setAccessType("offline"); // offline access
$client->setIncludeGrantedScopes(true); // incremental auth
$client->setAccessToken(
json_encode(
array(
'access_token' => $accessToken,
'expires_in' => 3600,
'token_type' => 'Bearer',
)
)
);
$client->setScopes(
array(
"https://www.googleapis.com/auth/userinfo.email",
"https://www.googleapis.com/auth/plus.me",
"https://www.googleapis.com/auth/plus.stream.write",
)
);
$client = $client->authorize();
// create the URL for this user ID
$url = sprintf('https://www.googleapis.com/plusDomains/v1/people/me/activities');
// create your HTTP request object
$headers = ['content-type' => 'application/json'];
$body = [
"object" => [
"originalContent" => "Happy Monday! #caseofthemondays",
],
"access" => [
"items" => [
["type" => "domain"],
],
"domainRestricted" => true,
],
];
$request = new Request('POST', $url, $headers, json_encode($body));
// make the HTTP request
$response = $client->send($request);
// did it work??
echo $response->getStatusCode().PHP_EOL;
echo $response->getReasonPhrase().PHP_EOL;
echo $response->getBody().PHP_EOL;
Following official documentation and some references from other posts
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…