2011-09-15 73 views
7

这只是片刻Google发布了其针对Google+社交网络的APIGoogle+ API - 通过电子邮件获取用户ID?

但是我怎样才能获得用户的数字ID?还是我被迫使用oAuth?

我知道它是写有在URL当您访问/国外的个人资料页,但如何programmaticaly与

信息做到这一点:
http://developers.google.com/+/api/latest/people/get
http://developers.google.com/+/api/oauth

+0

您正在使用哪个API。我正在研究他们的java api,并且看到了他们的plus.model包。我们无法在圈子中找到圈子或人,所以我认为我们无法获得这些人的ID。你想在你的圈子里随机获得朋友的ID吗? –

+0

当然是相关的,所以id的人在cicrles,所以这是他们的API的第一个版本中缺少的下一件事,该死的 –

+0

你有没有尝试任何其他的API –

回答

5

(我使用Python API)

使用OAuth时,您可以使用字符串'me'而不是userId,这样您就可以检索经过身份验证的用户的公共内容:

print service.activities().list(userId='me',collection='public').execute() 

我假设你正在使用PHP API(看你的标签),试着把'我'而不是userId。

编辑: 当检索验证用户的配置文件,您可以从‘ID’字段(JSON从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" 
    } 
} 
0

这是你可以做什么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); 
相关问题