我正尝试使用我运行的google drive.api
private static Credential authorize() throws Exception {
// load client secrets
InputStream in = new FileInputStream("C:\\Users\\orion\\OneDrive\\Documents\\GitHub\\teachervoiceorganization\\JavaProject\\client_id.json");
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY,
new InputStreamReader(in));
if (clientSecrets.getDetails().getClientId().startsWith("515427348790")
|| clientSecrets.getDetails().getClientSecret().startsWith("i50nkSMoqVegC0UdkD1W8g3Y")) {
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");
}
// set up authorization code flow
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport, JSON_FACTORY, clientSecrets,
Collections.singleton(DriveScopes.DRIVE_FILE)).setDataStoreFactory(dataStoreFactory)
.build();
// authorize
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
}
我遇到了问题
return new AuthorizationCodeInstalledApp(flow, new LocalServerReceiver()).authorize("user");
用户ID在哪里?我看过https://console.developers.google.com,没有运气。任何事情都会有所帮助。
答案 0 :(得分:0)
Google用户ID编码为从调用返回的JWT的sub
,以将Auth Code交换为令牌。您正在使用混淆所有内容的Java客户端库,因此任何人都可以猜测JWT令牌的公开位置。我的个人建议是丢弃该库,而直接直接调用两个OAuth URL。
步骤是:-
https://developers.google.com/identity/protocols/OAuth2WebServer
对此的描述非常好。 Nb,您需要包括email
范围和适当的Drive范围。