How to get user image through user id in Google plus?

前端 未结 2 1249
予麋鹿
予麋鹿 2020-12-06 12:19

I used to get user image through this URL

https://plus.google.com/s2/photos/profile/(user_id)?sz=150

but now what all I am getting is 404 error or no image.

2条回答
  •  渐次进展
    2020-12-06 12:42

    Earlier I have also the same problem for my site after so much of research and efforts I found solution from my self and i hope that will also work for you and solve your problem:

    Old Trick

    Google had changed their policy so the old trick for getting the Google profile image will not work now.

    e.g https://plus.google.com/s2/photos/profile/(user_id)?sz=150

    New Trick

    Get Request:

    https://www.googleapis.com/plus/v1/people/115950284...320?fields=image&key={YOUR_API_KEY}
    

    Response :200 OK

    {
        "image": 
        {
             "url": "https://lh3.googleusercontent.com/-OkM...AANA/ltpH4BFZ2as/photo.jpg?sz=50"
        }
    }
    

    Where YOUR_API_KEY is your Public API Access key which is generated through Credentials under APIs & Auth from https://console.developers.google.com/

    And While creating Public API access key you can choose Referers URL's from which this request should be made but for checking you should try by not adding any URL to it, if it works then go with URL of your site.

    You can choose other fields to send with URL which you may need from here.

    Happy Coding!!!

提交回复
热议问题