我想使用 php 发布到 google plus。但是google plus返回“403禁止”我希望你给我一段代码以使其成为可能。
这是我的身份验证功能:
global $client;
$client->setAuthConfig("/home/----");
$client->setRedirectUri("----");
$client->addScope("https://www.googleapis.com/auth/plus.stream.write");
$client->addScope("https://www.googleapis.com/auth/plus.me");
$authUrl = $client->createAuthUrl();
header("Location: $authUrl");
die;
这是我的新帖子功能:
$client->setAccessToken($token);
$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));
但结果是:
{ "error": { "errors": [ { "domain": "global", "reason": "forbidden", "message": "Forbidden" } ], "code": 403, "message": "Forbidden" } }
如您所知,现在有许多网站可以使用 google oauth 将新帖子发送到各种 google plus 帐户(不仅是 google 应用程序)(例如:buffer.com)