Not receiving Google OAuth refresh token

前端 未结 14 1438
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 07:38

I want to get the access token from Google. The Google API says that to get the access token, send the code and other parameters to token generating page, and the response

14条回答
  •  灰色年华
    2020-11-22 08:15

    In order to get the refresh token you have to add both approval_prompt=force and access_type="offline" If you are using the java client provided by Google it will look like this:

    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                HTTP_TRANSPORT, JSON_FACTORY, getClientSecrets(), scopes)
                .build();
    
    AuthorizationCodeRequestUrl authorizationUrl =
                flow.newAuthorizationUrl().setRedirectUri(callBackUrl)
                        .setApprovalPrompt("force")
                        .setAccessType("offline");
    

提交回复
热议问题