使用凭据-google drive sdk+java

使用凭据-google drive sdk+java,java,google-drive-api,google-oauth,google-oauth-java-client,Java,Google Drive Api,Google Oauth,Google Oauth Java Client,我需要上传文件到谷歌驱动器光盘使用谷歌驱动器SDK。我有简单的课程来做: public class DriveApiTest { private static String CLIENT_ID = "..."; private static String CLIENT_SECRET = "..."; // private static String REDIRECT_URI = "..."; private static String REDIRECT_URI

我需要上传文件到谷歌驱动器光盘使用谷歌驱动器SDK。我有简单的课程来做:

public class DriveApiTest {
    private static String CLIENT_ID = "...";
    private static String CLIENT_SECRET = "...";

    // private static String REDIRECT_URI = "...";
    private static String REDIRECT_URI = "...";

    static HttpTransport httpTransport = new NetHttpTransport();
    static JsonFactory jsonFactory = new JacksonFactory();
    static String parentId = "0B8Myj-AtyvWAWlNTQmpMdWxCRTQ";

    public static void start() throws IOException {
        GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
                httpTransport, jsonFactory, CLIENT_ID, CLIENT_SECRET,
                Arrays.asList(DriveScopes.DRIVE)).setAccessType("online")
                .setApprovalPrompt("auto").build();

        String url = flow.newAuthorizationUrl().setRedirectUri(REDIRECT_URI)
                .build();
        System.out
                .println("Please open the following URL in your browser then type the authorization code:");
        System.out.println("  " + url);
        try {
            Desktop.getDesktop().browse(new URI(url));
        } catch (URISyntaxException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String code = br.readLine();

        GoogleTokenResponse response = flow.newTokenRequest(code)
                .setRedirectUri(REDIRECT_URI).execute();

        GoogleCredential credential = new GoogleCredential()
                .setFromTokenResponse(response);

        Drive service = new Drive.Builder(httpTransport, jsonFactory,
                credential).setApplicationName("Test").build();

        File body = new File();
        body.setTitle("jeszcze inny Plik w podfolderze");
        body.setMimeType("text/csv");
        body.setParents(Arrays.asList(new ParentReference().setId(parentId)));

        java.io.File fileContent = new java.io.File(
                "C:\\Users\\TomekZ\\Desktop\\RoboczeExcele\\Person.csv");
        FileContent mediaContent = new FileContent("text/csv", fileContent);

        File file = service.files().insert(body, mediaContent).execute();
        System.out.println("File ID: " + file.getId());
    }
}
它正在工作,但用户必须从browse复制代码并将其粘贴到控制台中。有没有可能在不从browse复制代码的情况下进行复制?我从以下地方找到了类似的东西:

但我有个例外:

Exception in thread "main" java.io.IOException: toDerInputStream rejects tag type 56
我无法理解,也无法找出问题所在


我真的很惊讶使用credintials如此困难,我无法编写非常简单的应用程序。

如果您使用服务帐户,您需要在项目中生成服务帐户PKCS12文件,您需要提供服务帐户电子邮件,该电子邮件将与服务帐户一起生成,您需要下载密钥文件并提供路径服务帐户PKCS12文件路径。 这很简单

Exception in thread "main" java.io.IOException: toDerInputStream rejects tag type 56