Search code examples
google-apigoogle-oauth

How to download image from Google userinfo respones?


I want each player to have their google profile picture as their avatar. So i thougth i could use the link from userinfo to embed it on the my website.

I am able to login (via https://accounts.google.com/o/oauth2/v2/auth) and get data from the userinfo api (via https://openidconnect.googleapis.com/v1/userinfo), but when I try and get the picture I get a 400 bad request response.

The picture url: https://lh3.googleusercontent.com/a-/AD_cMMTQxBdVdae_-uIPzOwrjfiPwPplpdS11g9xMrgFNDJHMqc%5Cu003ds96-c

The acces token has these scopes:

I tried using the acces token in the Authorization header even though it should be public anyways, but no luck. I also tried searching for documentation but couldn't find anything for googleusercontent.com


Solution

  • I found out i should have used this api instead:

    Using the same token, the id from userinfo and personFields=photos I get a public link to the picture: https://lh3.googleusercontent.com/a/AAcHTtcasJNL-UkJ7S3uNGtNpQvwigQI_z3vQOle6zFlm7Zx7fA=s100