首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Google Drive凭据

Google Drive凭据
EN

Stack Overflow用户
提问于 2014-11-18 13:42:28
回答 2查看 904关注 0票数 0

我正在创建一个应用程序,在那里我必须存储的文件在谷歌驱动器的用户登录,所以任何用户登录,他可以存储数据在他的驱动器上。现在我有一个问题,如何从代码生成谷歌驱动凭证(clientId,clientSecret和refreshToken),就像我看到的所有示例一样,请转到谷歌控制台并在那里执行that.Is,我们可以使用java代码来实现。实际上,我需要使用google drive广告数据库存储。使用下面的代码:但这需要客户端id。

代码语言:javascript
复制
    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();

    ...
  }
}
EN

回答 2

Stack Overflow用户

发布于 2015-02-11 17:30:58

要获取客户端ID和客户端密钥,您需要首先在Google Developers控制台中创建或选择一个项目,并启用API。

您可以访问以下链接:

https://console.developers.google.com/apis/api/drive.googleapis.com/

票数 0
EN

Stack Overflow用户

发布于 2015-07-30 18:19:56

  1. 要获取客户端id,您需要首先从下面的链接https://console.developers.google.com/转到谷歌开发人员控制台。
  2. 单击创建项目并填写项目的名称。
  3. 单击API& AUTH,然后单击此处的凭据,您将看到创建新的客户端id链接。在这里,您将获得客户端id
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26987416

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档