【问题标题】:get profile picture from google plus从 google plus 获取个人资料图片
【发布时间】:2014-02-14 12:09:06
【问题描述】:

我在 django 应用程序中使用了谷歌应用引擎。我一直在使用 google 的用户 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 获取他们的头像。

Google API的用户类的user_id不同。

如何在我的应用程序中获取头像?

【问题讨论】:

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


    【解决方案1】:

    方法是在这里使用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->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"
    }
    

    【讨论】:

      【解决方案2】:

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

      根据user_id(),我的GoogleID 是xxx8005350796570706xx,而我的Google Plus 个人资料ID 是102445631084043565507,两者完全不同

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

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

      【讨论】:

      • 如何使用他们的电子邮件地址获取 GAvatar?
      • 我刚刚得到他们的头像,我的项目开发已经开始,所以在这期间我无法添加新的身份验证权限,如果有任何其他方式来获取头像。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-02-14
      • 2013-09-02
      • 2018-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      相关资源
      最近更新 更多