Notice: Undefined index: in /data/phpspider/phplib/misc.function.php on line 226
Java 谷歌API重定向更改不适用_Java_Google Api_Google Drive Api_Google Oauth_Google Api Java Client - Fatal编程技术网

Java 谷歌API重定向更改不适用

Java 谷歌API重定向更改不适用,java,google-api,google-drive-api,google-oauth,google-api-java-client,Java,Google Api,Google Drive Api,Google Oauth,Google Api Java Client,我一直在开发一个使用Google Drive API的应用程序,所以我使用OAuth id客户端重定向到http://localhost:8080/Callback但是现在我已经发布了,所以我把它改成了http://myURL/Callback 但是,更改似乎不适用,因为它要求打开以下URL: https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=my_client_id&redirect_

我一直在开发一个使用Google Drive API的应用程序,所以我使用OAuth id客户端重定向到
http://localhost:8080/Callback
但是现在我已经发布了,所以我把它改成了
http://myURL/Callback

但是,更改似乎不适用,因为它要求打开以下URL:

https://accounts.google.com/o/oauth2/auth?access_type=offline&client_id=my_client_id&redirect_uri=http://localhost:46517/Callback&response_type=code&scope=https://www.googleapis.com/auth/drive
如果我试图打开它,我会明显地得到
错误:redirect\u uri\u mismatch
,因为我删除了localhost作为授权重定向

下面是我用来连接GoogleAPI的代码

public FileSP downloadFile(String fileId, String clientSecretPath){

    FileSP fileSP = null;
    String extension = null;
    try {

        Drive driveService = _getDriveService(clientSecretPath);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        File file = driveService.files().get(fileId).execute();
       //do stuff

    } catch (IOException e) {
        String mess = "downloadFile(): " 
                + (e.getMessage()!=null?". "+e.getMessage():"")
                + (e.getCause()!=null?". "+e.getCause():"");
        logger.error(mess);
    }
    return fileSP;
}


private Drive _getDriveService(String clientSecretPath) throws IOException {
    Credential credential = _authorize(clientSecretPath);
    return new Drive.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, credential)
            .setApplicationName(APPLICATION_NAME)
            .build();
}


private Credential _authorize(String clientSecretPath) throws IOException {

    GoogleClientSecrets clientSecrets =
        GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(new FileInputStream(clientSecretPath)));

    GoogleAuthorizationCodeFlow flow =
            new GoogleAuthorizationCodeFlow.Builder(
                    HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES)
            .setDataStoreFactory(DATA_STORE_FACTORY)
            .setAccessType("offline")
            .build();
    Credential credential = new AuthorizationCodeInstalledApp(
        flow, new LocalServerReceiver()).authorize("user");
    System.out.println(
            "Credentials saved to " + DATA_STORE_DIR.getAbsolutePath());
    return credential;
}

重定向错误页面应该向您显示它来自的重定向URI和您正在发送的重定向URI。记住,它需要精确匹配。顺便说一句,你可以有多个本地主机,这样你就可以离开本地主机了。它说问题是,我希望它是myurl.com/Callback,而不是localhost,但它仍然不断地要求它(这也是为什么我删除了localhost作为重定向,只是为了确定)你是在运行这个编译的还是在运行它调试?要从你的网站上运行它,你必须把它放在那里并在那里运行。库自动从其来源发送重定向uri。如果它说的是localhost,那么对我来说意味着你正在运行这个调试。不,我正在编译它。我想它可能是
newauthorizationCodeInstalledApp(flow,newlocalServerReceiver()).authorization(“用户”)
因为LocalServerReceiver说在“localhost”上启动服务器的构造函数选择了一个未使用的端口,但我不知道应该使用什么来代替它it@DaImTo也许使用
newlocalserverreceiver.Builder().setHost(“mydomain.com”).build()
会有所帮助?