从谷歌加上获取个人资料图片

时间:2014-02-14 12:09:06

标签: django google-app-engine google-profiles-api

我使用了django应用程序的谷歌应用程序引擎。我一直在使用谷歌的用户api登录我的网站,并从中获取当前的用户电子邮件地址,但我必须获得在Google Plus帐户上发布的个人资料图片。

我正在使用

获取他们的个人资料照片
<img src="https://plus.google.com/s2/photos/profile/<user_id>?sz=100" width="100" height="100">

在谷歌api。

用户类还提供user_id,但我无法使用user_id获取他们的个人资料照片。

&LT; USER_ID&GT;用户类Google API的user_id不同。

如何在我的应用程序中获取个人资料图片?

2 个答案:

答案 0 :(得分:3)

这样做的方法是在这里使用google + api:https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=me&_h=2&

这是为当前经过身份验证的用户提取图像的请求。

GET https://www.googleapis.com/plus/v1/people/me?key={YOUR_API_KEY}

你会得到像这样的json响应,并且很容易解析它并提取image-&gt; url值来显示。

{
    "kind": "plus#person",
    "etag": "\"XxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXxXx\"",
    "gender": "male",
    "emails": [
        {
            "value": "jbrahy@XxXxXxXx.com",
            "type": "account"
        }
    ],
    "objectType": "person",
    "id": "XxXxXxXxXxXxXxXxXxXxXxXx",
    "displayName": "John Brahy",
    "name": {
        "familyName": "Brahy",
        "givenName": "John"
    },
    "url": "https://plus.google.com/XxXxXxXxXxXxXxXxXxXxXxXx",
    "image": {
        "url": "https://lh3.googleusercontent.com/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/photo.jpg?sz=50"
    },
    "isPlusUser": true,
    "language": "en",
    "circledByCount": 2,
    "verified": false,
    "cover": {
        "layout": "banner",
        "coverPhoto": {
            "url": "https://lh5.googleusercontent.com/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/XxXxXxXx/Green%2BGrass.jpg",
            "height": 240,
            "width": 420
        },
        "coverInfo": {
            "topImageOffset": 0,
            "leftImageOffset": 0
        }
    },
    "domain": "XxXxXxXx-x.com"
}

答案 1 :(得分:0)

如果你问的是关于ids ......

根据user_id(),我的Google ID为xxx8005350796570706xx,我的Google Plus个人资料ID为102445631084043565507,这些ID完全不同

您需要询问用户他的G +个人资料或通过oAth2.0对他进行身份验证才能获得阅读其个人资料的权限。

此外,如果您有他的电子邮件地址,您可以使用GAvatar。

相关问题