7

谷歌刚刚发布了其用于 Google+ 社交网络的 API

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

我知道当您访问您的/外国个人资料页面时它写在 URL 中,但是如何以编程方式使用

信息: http:
//developers.google.com/+/api/latest/people/get
http://developers.google.com/+/api/oauth

4

2 回答 2

5

(我正在使用 Python API)

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

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

我假设您正在使用 PHP API(查看您的标签),请尝试使用“我”而不是 userId。

编辑: 检索经过身份验证的用户的个人资料时,您可以从“id”字段中获取 userId(来自http://developers.google.com/+/api/的 JSON 响应):

{
  "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"
  }
}
于 2011-09-16T02:42:08.113 回答
1

这是您可以在 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);
于 2012-04-03T10:31:56.047 回答