Google drive api 谷歌硬盘凭证
我正在创建一个应用程序,在这个应用程序中,我必须将登录用户的文件存储在谷歌硬盘中,这样哪个登录用户都可以将数据存储在他的硬盘上。现在我遇到了一个问题,如何从代码中生成Google驱动器凭据clientId、clientSecret和refreshToken,正如我看到的所有示例,请as转到Google控制台并执行此操作。我们是否可以使用java代码实现它。实际上我需要使用谷歌硬盘的广告数据库存储。 使用了以下代码:但需要客户端idGoogle drive api 谷歌硬盘凭证,google-drive-api,Google Drive Api,我正在创建一个应用程序,在这个应用程序中,我必须将登录用户的文件存储在谷歌硬盘中,这样哪个登录用户都可以将数据存储在他的硬盘上。现在我遇到了一个问题,如何从代码中生成Google驱动器凭据clientId、clientSecret和refreshToken,正如我看到的所有示例,请as转到Google控制台并执行此操作。我们是否可以使用java代码实现它。实际上我需要使用谷歌硬盘的广告数据库存储。 使用了以下代码:但需要客户端id public class Main { public
public class Main
{
public static void main(String[] args)
{
String clientId = "...";
String clientSecret = "...";
HttpTransport httpTransport = new NetHttpTransport();
JsonFactory jsonFactory = new JacksonFactory();
GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
httpTransport,
jsonFactory,
clientId,
clientSecret,
Arrays.asList(DriveScopes.DRIVE)
)
.setAccessType("online")
.setApprovalPrompt("auto").build();
String redirectUri = "urn:ietf:wg:oauth:2.0:oob";
String url =
flow
.newAuthorizationUrl()
.setRedirectUri(redirectUri)
.build();
System.out.println("Please open the following URL in your browser then type the authorization code:");
System.out.println(" " + url);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String code = br.readLine();
GoogleTokenResponse response =
flow
.newTokenRequest(code)
.setRedirectUri(redirectUri)
.execute();
GoogleCredential credential =
new GoogleCredential()
.setFromTokenResponse(response);
Drive service =
new Drive.Builder(httpTransport, jsonFactory, credential)
.build();
...
}
}
要获得客户ID和客户机密,您需要首先在Google开发者控制台中创建或选择一个项目并启用API 您可以点击以下链接: 要获取客户端id,首先需要从下面的链接转到google开发者控制台 单击CreateProject并填写项目名称 单击API和AUTH,然后单击此处的凭据,您将看到创建新客户端id链接。这是你的客户id