PayPal沙箱获取访问令牌API拒绝我的Java代码工作
我试图访问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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论