How to get access token using gmail api

前端 未结 7 1016
遇见更好的自我
遇见更好的自我 2021-01-01 22:29

I got the authorization code following this document. But when I tried to get access token, I always got errors. Can anyone help me ?

public String AccessTok         


        
7条回答
  •  再見小時候
    2021-01-01 23:11

    I think I understand what's wrong:

    1. as @newhouse said, you should POST to https://www.googleapis.com/oauth2/v4/token and not https://accounts.google.com/o/oauth2/token (@newhouse I gave you a +1 :) )

      (https://www.googleapis.com/oauth2/v4/token is for getting the authorization_code and https://accounts.google.com/o/oauth2/token is for getting the code).

    2. You can't use the same code more than once.

      Everything else seems in order so, if you keep getting 400, you are probably trying to use the code you got more than one time (then you'll get 400 every time, again and again).

    * You should also lose the con.setRequestProperty("Host", "www.googleapis.com");

提交回复
热议问题