我正在使用 java ( https://developers.google.com/drive/v2/web/quickstart/java ) 跟踪 Google Drive 的 API,并且有这行代码读取我的项目目录中的 .json 文件(我将其复制到那里),其中包含 client_id 和 client_secret 。
// Load client secrets.
InputStream in = GoogleDrive.class.getResourceAsStream("client_id.json");
this.clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));
// Build flow and trigger user authorization request.
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
.setDataStoreFactory(DATA_STORE_FACTORY)
.setAccessType("offline")
.build();
我制作了一个 GoogleDrive.java 类,使登录、上传等变得更加容易。
如何对 .json 文件中的信息进行硬编码,并让 google 将其“加载”到 clientsecrets,以便我也可以在其他应用程序中使用此类。我是 REST 方面的新手,因此如果能提供一步一步的说明,我们将不胜感激。
谢谢大家。
最佳答案
找到了答案,使用这个方法(嗯,相同的方法,不同的签名)可以解决问题:)
public GoogleAuthorizationCodeFlow.Builder(HttpTransport transport,
JsonFactory jsonFactory,
String clientId,
String clientSecret,
Collection<String> scopes)
关于java - 如何在我的 java 应用程序中对 Google OAuth 的 client_id 和 client_secret 进行硬编码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35757925/