在我的生产服务器

时间:2018-04-05 07:54:18

标签: java spring-boot google-spreadsheet-api

enter image description here

我正在使用Google提供的以下步骤在Google表格中撰写数据

https://developers.google.com/sheets/api/quickstart/java

写这篇文章时,我要求我在本地系统浏览器中使用以下Url进行授权

  

https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=982564880549-brnp1o1a8gq2cmvrn8r4d7ctial9eu8o.apps.googleusercontent.com&redirect_uri=http://localhost:53670/Callback&response_type=code&scope=https://www.googleapis.com/auth/spreadsheets.readonly%20https://www.googleapis.com/auth/drive

我做了同样的事情,并且在我的本地系统上工作正常。现在我在生产服务器上移动了相同的代码,它仍然显示我的localhost为redirect_uri,这对生产服务器不起作用。

上面的图片是我创建项目的时候,我已经提供了"授权的重定向URI"我的服务器,我也下载了json的授权

当我在生产服务器上部署我的应用程序时,我得到了Url

  

https://accounts.google.com/o/oauth2/auth?access_type=online&client_id=800348449492-q8rqvogvi18qkdjimr15e3gvmb1o3dvf.apps.googleusercontent.com&redirect_uri=http://localhost:55424/Callback&response_type=code&scope=https://www.googleapis.com/auth/spreadsheets.readonly%20https://www.googleapis.com/auth/drive

但是当我在浏览器中打开URL时出现以下错误:

enter image description here

Json下载的是

  

{"网络" {" CLIENT_ID":" 800348449492-q8rqvogvi18qkdjimr15e3gvmb1o3dvf.apps.googleusercontent.com"" PROJECT_ID":& #34; lasttry-200209"" auth_uri":" https://accounts.google.com/o/oauth2/auth"" token_uri":" {{3} }"" auth_provider_x509_cert_url":" https://accounts.google.com/o/oauth2/token"" client_secret":" NUnoK-pQx560IEVst-VicWJU" " redirect_uris中":[" https://www.googleapis.com/oauth2/v1/certs&#34]," javascript_origins":[" https://sandbox.sonicjobs.net/hunter-1.7.0/api/v2/admin/oauth2callback"] }}

我的代码是

public static Sheets getSheetsService() throws IOException {
        Credential credential = authorize();
        return new Sheets.Builder(HunterUtil.HTTP_TRANSPORT, HunterUtil.JSON_FACTORY, credential)
                .setApplicationName(HunterUtil.APPLICATION_NAME)
                .build();
    }


public static Credential authorize() throws IOException {

FileInputStream in=new FileInputStream("/data/GoogleDriveCredentials/client_secret.json");
        GoogleClientSecrets clientSecrets =
            GoogleClientSecrets.load(HunterUtil.JSON_FACTORY, new InputStreamReader(in));

        // Build flow and trigger user authorization request.
        GoogleAuthorizationCodeFlow flow =
                new GoogleAuthorizationCodeFlow.Builder(
                        HunterUtil.HTTP_TRANSPORT, HunterUtil.JSON_FACTORY, clientSecrets, HunterUtil.SCOPES)
                .setDataStoreFactory(HunterUtil.DATA_STORE_FACTORY)
                .setAccessType("online")
                .build();
        log.info("Redirect URL is:: "+new LocalServerReceiver().getRedirectUri());
        log.info("Redirect URL is:: "+new LocalServerReceiver().getCallbackPath());

        Credential credential = new AuthorizationCodeInstalledApp(
            flow, new LocalServerReceiver()).authorize("user");

        return credential;
    }

0 个答案:

没有答案