我们希望让我们的GAE for java应用程序从谷歌驱动器中读取文档以满足应用程序的特定要求。
对于同样的情况,我试图引用https://developers.google.com/drive/auth/web-server
但是,我无法理解代码流。没有提到像从哪里获得下面代码中提到的authorizationCode:
public static Credential getCredentials(String authorizationCode, String state)
throws CodeExchangeException, NoRefreshTokenException, IOException {
String emailAddress = "";
try {
Credential credentials = exchangeCode(authorizationCode);
Userinfo userInfo = getUserInfo(credentials);
String userId = userInfo.getId();
emailAddress = userInfo.getEmail();
if (credentials.getRefreshToken() != null) {
storeCredentials(userId, credentials);
return credentials;
} else {
credentials = getStoredCredentials(userId);
if (credentials != null && credentials.getRefreshToken() != null) {
return credentials;
}
}
} catch (CodeExchangeException e) {
gae for java和google drive之间集成的任何工作示例?
答案 0 :(得分:1)
如果您尝试进行离线访问,首先您必须获得可以兑换访问令牌和刷新令牌的授权码。
启用Google云端硬盘服务 创建客户端ID然后,获取授权码,例如:
https://accounts.google.com/o/oauth2/auth?access_type=offline
&approval_prompt=auto
&client_id=[your id]
&redirect_uri=[url]
&response_type=code
&scope=[access scopes]
&state=/profile
之后,您可以调用exchangeCode(),其参数将是您之前检索过的授权代码。