简体   繁体   English

Google Api-获取用户详细信息

[英]Google Api - Get users details

I am using the Google Api PHP Client. 我正在使用Google Api PHP客户端。

I want to get the details of the user who has logged in. 我想获取已登录用户的详细信息。

I am setting the following Scopes 我正在设定以下范围

$client->setScopes('https://www.googleapis.com/auth/userinfo.profile');

$request = new apiHttpRequest("https://www.googleapis.com/oauth2/v1/userinfo?alt=json");
  $userinfo = $client->getIo()->authenticatedRequest($request);


  $response = json_encode(simplexml_load_string($userinfo->getResponseBody()));
  print "<pre>" . print_r(json_decode($response, true), true) . "</pre>";

But i am not able to get the jSON from the above code. 但是我无法从上面的代码中获取jSON。

Wanted to Deleted the Question but didnt find any Answer that uses the PHP Client. 想要删除问题,但找不到任何使用PHP客户端的答案。 so answering my own question 所以回答我自己的问题

Just by replacing 只需更换

$response = json_encode(simplexml_load_string($userinfo->getResponseBody()));

by 通过

$response = $userinfo->getResponseBody();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM