【发布时间】:2019-06-20 16:57:24
【问题描述】:
我正在使用 Java 企业版开发一个网络应用程序,我需要 Google Drive API。在某些时候,我需要让客户“授权”访问他们的云端硬盘,为此(根据我的理解),我需要获取 Google API 凭据(oAuth 的),但这是一个漫长的过程,因为我我在做这个学校项目,我等不及了。所以我需要一种方法来测试 API,而不必经历获取已发布应用所需凭据的繁重过程。
我正在这个项目上测试 Drive API https://github.com/google/google-api-java-client-samples/tree/master/drive-cmdline-sample
问题出在这个函数上
private static Credential authorize() throws Exception {
// load client secrets
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(testApi.class.getResourceAsStream("/client_secrets.json")));
if (clientSecrets.getDetails().getClientId().startsWith("Enter")
|| clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
System.out.println(
"Enter Client ID and Secret from https://code.google.com/apis/console/?api=drive "
+ "into drive-cmdline-sample/src/main/resources/client_secrets.json");
System.exit(1);
}
我需要以某种方式获得client_secrets.json,但我不能没有凭据,或者至少,这是我从研究和阅读中了解到的。
如果有帮助,这个函数是从com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; 导入的。
谢谢!
【问题讨论】:
标签: jakarta-ee google-drive-api credentials