Google OAuth REST API: getting user’s email address


Step 1: create google authorization url with scope must include https://www.googleapis.com/auth/userinfo.email

Example:

https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A//www.googleapis.com/auth/userinfo.email%20https%3A//www.googleapis.com/auth/drive.file&access_type=offline&include_granted_scopes=true&response_type=code&state=login&redirect_uri=https%3A//yourdomain.com/auth/google&client_id=your_client_id.apps.googleusercontent.com

Step 2: get access_token

Documentation: https://developers.google.com/identity/protocols/oauth2/web-server#httprest_3

Step 3:

Method 1:

https://www.googleapis.com/oauth2/v3/userinfo?access_token=your_access_token

Method 2:

curl -H "Authorization: Bearer your_access_token" https://www.googleapis.com/oauth2/v3/userinfo

Result:

{
  "sub": "108378817912896508886",
  "picture": "https://lh3.googleusercontent.com/a/default-user\u003ds96-c",
  "email": "youremail@gmail.com",
  "email_verified": true
}

Leave a Reply