简体   繁体   中英

get profile picture from google plus

I have used google app engine with django application. I have been using the user api from google to login in my website and also getting the current user email address from that, but i have to get profile picture which is uploded on the google plus account.

I am getting their profile picture using,

<img src="https://plus.google.com/s2/photos/profile/<user_id>?sz=100" width="100" height="100">

in google api.

User class also provides user_id but I cannot get their profile picture using that user_id .

<user_id> and user_id of user class of Google API is different.

How to get the profile picture in my application?

The way to do it is to use the google+ api here: https://developers.google.com/apis-explorer/#p/plus/v1/plus.people.get?userId=me&_h=2&

This is the request to pull the image for the currently authenticated user.

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

You'll get a json response like this and it's really easy to parse that and pull out the image->url value to display.

{
    "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"
}

If you are asking the about the ids...

My GoogleID according to user_id() is xxx8005350796570706xx and my Google Plus profile ID is 102445631084043565507 which are totally different

You need to ask the user for his G+ profile or authenticate him via oAth2.0 to get permissions to read his profile.

Also if you have his email address you could use GAvatar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM