You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过需认证的代理获取FCM OAuth访问令牌?

解决带认证代理下获取Google Access Token的407错误

你遇到的407错误核心原因是:仅配置了代理的地址和端口,却未提供代理要求的用户名密码认证信息。针对你使用的google-api-client-1.23.0版本,只需在构建NetHttpTransport时补充代理认证逻辑即可解决。

修改后的完整代码片段:

HttpTransport httpTransport = null;         
NetHttpTransport.Builder netHttpTransportBuilder = new NetHttpTransport.Builder();

// 设置代理地址和端口
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(
    httpClient.getHostConfiguration().getProxyHost(), 
    httpClient.getHostConfiguration().getProxyPort()
));
netHttpTransportBuilder.setProxy(proxy);

// 添加代理认证逻辑
Authenticator proxyAuthenticator = new Authenticator() {
    @Override
    protected PasswordAuthentication getPasswordAuthentication() {
        // 替换为你的代理实际用户名和密码
        return new PasswordAuthentication(
            "proxy_username",
            "proxy_password".toCharArray()
        );
    }
};
netHttpTransportBuilder.setProxyAuthenticator(proxyAuthenticator);

httpTransport = netHttpTransportBuilder.build();        

GoogleCredential googleCredential = null;
// 创建带代理认证的Google Credential
googleCredential = GoogleCredential.fromStream(
    new FileInputStream(filePath), 
    httpTransport, 
    com.google.api.client.googleapis.util.Utils.getDefaultJsonFactory()
).createScoped(Arrays.asList(arr));

关键说明:

  • 通过setProxyAuthenticator方法为NetHttpTransport注入代理认证逻辑,Authenticator的getPasswordAuthentication方法负责返回代理的用户名和密码。
  • 务必将代码中的proxy_username和proxy_password替换为你实际的代理认证信息。

内容的提问来源于stack exchange,提问作者prathyusha magam

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.26 17:02:44