7

Google が Google+ ソーシャル ネットワークの API を公開したのはほんの少しの瞬間です。

しかし、どうすれば user の数値 ID を取得できますか? または、oAuth を使用する必要がありますか?

あなた/外国のプロフィールページにアクセスするとURLに書かれていることは知っていますが、プログラムでそれを行う方法

情報:
http://developers.google.com/+/api/latest/people/get
http://developers.google.com/+/api/oauth

4

2 に答える 2

5

(私は Python API を使用しています)

OAuth を使用する場合、userId の代わりに文字列「me」を使用できます。これにより、認証されたユーザーのパブリック コンテンツを取得できます。

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

PHP API を使用していると思います (タグを見てください)。userId の代わりに「me」を入れてみてください。

編集: 認証されたユーザーのプロファイルを取得するときに、「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 に答える