我一直在尝试设置一个应用程序,让它与 Google API 之一对话。当我将它部署到我的 linux 服务器(仅限 shell)时,它确实要求我使用重定向 URI 值“请在浏览器中打开以下地址” localhost:some_port
。
我无法从我的 linux 机器访问它,也无法在其他一些基于 UI 的浏览器上打开它,因为 redirect_uri 总是基于 localhost。
我已经将我的服务器公共域添加到重定向 URI 列表中,但它仍然总是使用本地主机地址生成。
我怎样才能从同意屏幕中获取令牌,因为它总是将我重定向到我的 linux 服务器上的 localhost?
创建连接的代码(在本地主机上一切正常,所以这里没有错误):
InputStream in = SearcherApplication.class.getResourceAsStream("/client_secret.json");
GoogleClientSecrets clientSecrets =
GoogleClientSecrets.load(jsonFactory, new InputStreamReader(in));
GoogleAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow.Builder(
httpTransport, jsonFactory, clientSecrets, Collections.singleton(YOUTUBE_READONLY))
.setDataStoreFactory(dataStoreFactory)
.setAccessType("offline")
.build();
return new AuthorizationCodeInstalledApp(
flow, new LocalServerReceiver()).authorize("user");
找到该选项的位置。而不是new LocalServerReceiver()
设置以下代码:new LocalServerReceiver.Builder() .setHost("my.awesome.server") .setPort(8080) .setCallbackPath("/Callback") .build()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句