我遵循所有这些步骤.
https://developers.google.com/+/web/signin/
我有客户端和客户端的秘密.
使用OAuth2,您可以通过scope参数请求权限. (
Documentation.)我想象你想要的范围是
https://www.googleapis.com/auth/userinfo.email和
https://www.googleapis.com/auth/userinfo.profile.
原文链接:https://www.f2er.com/php/131024.html然后,获取访问令牌后,获取配置文件信息就很简单了. (我假设您已经能够兑换访问令牌的返回的授权码?)只需获得一个获取请求,到https://www.googleapis.com/oauth2/v1/userinfo?access_token= {accessToken},该访问返回一个JSON数组的配置文件数据,包括电子邮件:
{ "id": "00000000000000","email": "fred.example@gmail.com","verified_email": true,"name": "Fred Example","given_name": "Fred","family_name": "Example","picture": "https://lh5.googleusercontent.com/-2Sv-4bBMLLA/AAAAAAAAAAI/AAAAAAAAABo/bEG4kI2mG0I/photo.jpg","gender": "male","locale": "en-US" }
没有保证,但尝试这样:
$url = "https://www.googleapis.com/oauth2/v1/userinfo"; $request = apiClient::$io->makeRequest($client->sign(new apiHttpRequest($url,'GET'))); if ((int)$request->getResponseHttpCode() == 200) { $response = $request->getResponseBody(); $decodedResponse = json_decode($response,true); //process user info } else { $response = $request->getResponseBody(); $decodedResponse = json_decode($response,true); if ($decodedResponse != $response && $decodedResponse != null && $decodedResponse['error']) { $response = $decodedResponse['error']; } } }