Pregunta

I am using the Google Api PHP Client.

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.

¿Fue útil?

Solución

Wanted to Deleted the Question but didnt find any Answer that uses the PHP Client. so answering my own question

Just by replacing

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

by

$response = $userinfo->getResponseBody();
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top