我通过浏览器 Javascript 获取请求令牌。
下面的 Java 代码可以用它来换取访问令牌。
import com.google.api.client.googleapis.auth.oauth2.GoogleTokenResponse;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeTokenRequest;
GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(TRANSPORT, JSON_FACTORY, clientId, clientSecret, authCode, "postmessage").execute();
我的问题是谷歌图书馆调用带有相当大的足迹。
因此,我尝试了 scribe(Kobee1203 oauth 2.0 fork)。它对我不起作用:
  OAuthService service = new ServiceBuilder()
                                .provider(GoogleApi20.class)
                                .apiKey(apiKey)
                                .apiSecret(apiSecret)
                                .scope(SCOPE)
                                .grantType(OAuthConstants.GRANT_TYPE_AUTHORIZATION_CODE)
                                .accessType("offline")
                                .build();
  Verifier verifier = new Verifier(authcode);
  Token accessToken = service.getAccessToken(null, verifier);
谷歌响应和错误抱怨和间接重定向 url。api 控制台中没有设置重定向 url,并且没有之前的代码也可以正常工作。
我想要一个基于 Java 的轻量级解决方案,用请求交换访问令牌以进行一次基本的授权调用。它不一定是抄写员。