Google+服务器端注册我的应用程序

时间:2013-04-29 06:42:34

标签: php google-plus

嘿,我从我的localhost页面获取授权代码。如何使用此授权码获取访问令牌

1 个答案:

答案 0 :(得分:2)

如果您使用Google APIs Client Library for PHP,这可能是最简单的。

$client = new Google_Client();
$client->setApplicationName(APPLICATION_NAME);
$client->setClientId(CLIENT_ID);
$client->setClientSecret(CLIENT_SECRET);

然后,当您拥有授权码时,您可以致电:

$client->authenticate($code);
$token = json_decode($client->getAccessToken());
access_token = $token->access_token;

然后,您可以在请求中使用访问令牌,或使用客户端库访问各种Google API(这更容易)。

另请参阅https://developers.google.com/+/quickstart/phphttps://github.com/googleplus/gplus-quickstart-php/以获取完整的流程示例。