试图找到如何从 PHP 发布到 google plus wall 但即使使用 api explorer 也得到403
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Forbidden"
}
],
"code": 403,
"message": "Forbidden"
}
}
我的 PHP 代码如下所示:
$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;
遵循官方文档和其他帖子的一些参考资料