我们想让我们的 GAE for java 应用程序从谷歌驱动器读取文档以满足应用程序的特定要求。
同样,我试图引用 https://developers.google.com/drive/auth/web-server
但是,我无法理解代码流程。没有提及从哪里获取授权代码,如下面的代码所示:
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 之间集成的工作示例吗?
最佳答案
如果您尝试离线访问,首先您必须获得授权码,该授权码可以兑换为访问 token 和刷新 token 。
1) 从 Google APIs console 启用 Google 云端硬盘服务
2) 为 web applications 创建客户端 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() ,它的参数将是您之前检索到的授权码。
关于java - 对谷歌驱动器实现服务器端授权的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17057978/