【发布时间】:2017-02-27 06:58:22
【问题描述】:
我正在关注guide 构建一个 Android 应用程序,该应用程序请求用户使用 Gmail 范围为只读的帐户访问权限,然后生成 authCode 并将其发送到后端服务器。
后端服务器然后接收 authCode 并使用它生成 accessToken。这是代码:
private static String CLIENT_SECRET_FILE = "/client_secret.json";
private static String REDIRECT_URI = "";
String accessToken = null;
// Exchange auth code for access token
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JacksonFactory.class.newInstance(),
new FileReader(CLIENT_SECRET_FILE));
GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(),
JacksonFactory.class.newInstance(), "https://www.googleapis.com/oauth2/v4/token",
clientSecrets.getDetails().getClientId(), clientSecrets.getDetails().getClientSecret(), authCode,
REDIRECT_URI).execute();
accessToken = tokenResponse.getAccessToken();
现在使用此访问令牌,后端服务器需要使用 Gmail SDK 访问 Gmail。
我如何做到这一点?
【问题讨论】:
标签: java gmail access-token