Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 246
Jay Bhalodi Avatar asked Oct 21 '22 14:10

Jay Bhalodi


1 Answers

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": "[email protected]",
            "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"
}
like image 186
jbrahy Avatar answered Oct 23 '22 11:10

jbrahy