It's just a few moments Google published its API for Google+ social network
But how can I get numeric ID of user ? Or am I forced to use oAuth?
I know it's written there in URL when you access your/foreign profile page, but how to do it programmaticaly with
info:
http://developers.google.com/+/api/latest/people/get
http://developers.google.com/+/api/oauth
(I'm using the Python API)
When using OAuth you can use the string 'me' instead of userId, that way you can retrieve the public content of the authenticated user:
print service.activities().list(userId='me',collection='public').execute()
I assume you are using PHP API (looking at your tags), try putting 'me' instead of userId.
Edit: When retrieving the authenticated users' profile, you can get the userId from the "id" field (JSON response taken from http://developers.google.com/+/api/):
{
"kind": "plus#person",
"id": "118051310819094153327",
"displayName": "Chirag Shah",
"url": "https://plus.google.com/118051310819094153327",
"image": {
"url": "https://lh5.googleusercontent.com/-XnZDEoiF09Y/AAAAAAAAAAI/AAAAAAAAYCI/7fow4a2UTMU/photo.jpg"
}
}
This is what you can do in php
$client->setScopes(array('https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/userinfo.email'));
$url = 'https://www.googleapis.com/oauth2/v1/userinfo';
$request = $client->getIo()->authenticatedRequest(new apiHttpRequest($url));
if ($request->getResponseHttpCode() != 200) {
throw new apiException("http code: " . $request->getResponseHttpCode() . ", response body: " . $request->getResponseBody());
}
$temp = json_decode($request->getResponseBody(), true);
print_r($temp);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With