PayPal沙箱获取访问令牌API拒绝我的Java代码工作

发布于 2025-01-23 01:06:06 字数 1277 浏览 1 评论 0原文

我试图访问REST API,以获取PayPal访问令牌,但那里的某些内容不起作用。我一直从代码中获取代码403(禁止)。

该代码基于雅加达平台9.1.0上可用的泽西式JAX-RS隐含物。如下:

try {
            Invocation.Builder builder = client.target("https://api-m.sandbox.paypal.com/")
                        .path("v1/oauth2/token")
                        .request()
                        .accept("application/json")
                        .acceptLanguage("en_US")
                        .header("Authorization", this.httpHeaders.get("Authorization"))
                            .header("Content-Type", "application/x-www-form-urlencoded");
            response = builder.post(Entity.entity("grant_type=client_credentials", MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

this.httpheaders.get(“授权”)是我存储标准'basic' + base64表示的地方,如果username:password。

为了验证我的防火墙不是问题,我通过卷曲从Windows 10命令行访问了同一API,它可以找到(我可以找到一个适当的JSON块的200个OK响应):

curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" \
    -u "<CLIENT_ID>:<CLIENT_SECRET>" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "grant_type=client_credentials"  

显然我在这里做错了什么。感谢您的帮助,告诉我需要解决什么。

I have tried to access the REST api in order to get a PayPal access token, but something doesn't work there. I keep on getting code 403 (Forbidden) from the code.

The code is based on Jersey Jax-RS implmentation that's available on the Jakarta platform 9.1.0. Here's how it looks like:

try {
            Invocation.Builder builder = client.target("https://api-m.sandbox.paypal.com/")
                        .path("v1/oauth2/token")
                        .request()
                        .accept("application/json")
                        .acceptLanguage("en_US")
                        .header("Authorization", this.httpHeaders.get("Authorization"))
                            .header("Content-Type", "application/x-www-form-urlencoded");
            response = builder.post(Entity.entity("grant_type=client_credentials", MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class);
        } catch (Exception e) {
            e.printStackTrace();
        }

the this.httpHeaders.get("Authorization") is where I stored the standard 'Basic ' + the base64 representation if the username:password.

In order to verify it's not an issue with my firewall i accessed the same api from windows 10 command line via cUrl and it works just find (I get a 200 ok reponse with a proper json block):

curl -v -X POST "https://api-m.sandbox.paypal.com/v1/oauth2/token" \
    -u "<CLIENT_ID>:<CLIENT_SECRET>" \
    -H "Content-Type: application/x-www-form-urlencoded" \
    -d "grant_type=client_credentials"  

Obviously I am doing something wrong here. I would appreciate your help to tell me what is needed to be fixed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文