如何使用REST请求获取Paypal访问令牌

编程入门 行业动态 更新时间:2024-10-25 14:31:54
本文介绍了如何使用REST请求获取Paypal访问令牌的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使其正常运行 developer.paypal/webapps/developer/docs/integration/direct/make-your-first-call/ 使用Java + Jersey应用程序.似乎我在POST参数中缺少了一些东西.

I'm trying to get this working developer.paypal/webapps/developer/docs/integration/direct/make-your-first-call/ Using Java + Jersey application. It seems like I'm missing something in POST params.

public String getPaypalToken() { Client client = Client.create(); WebResource webResource = client.resource("api.sandbox.paypal/v1/oauth2/token"); MultivaluedMap<String, String> queryParams = new MultivaluedMapImpl(); queryParams.add("username", CLIENT_ID + ":" + SECRET ); queryParams.add("grant_type", "client_credentials"); ClientResponse response = webResource.accept("application/json").acceptLanguage("en_US").type("application/x-www-form-urlencoded").post(ClientResponse.class, queryParams); return response.toString(); }

使用我之前得到的代码:POST api.sandbox.paypal /v1/oauth2/token 返回的响应状态为401未经授权.

Using previous code I got: POST api.sandbox.paypal/v1/oauth2/token returned a response status of 401 Unauthorized.

此CURL命令行选项可以正常工作:

This CURL command line option just works fine:

curl -X POST api.sandbox.paypal/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" -d "grant_type=client_credentials"

任何建议将不胜感激.

Any suggestions will be appreciated. J.

推荐答案

只需共享我的解决方案:

Just sharing my solution:

Dictionary<string, string> sdkConfig = new Dictionary<string, string>(); sdkConfig.Add("mode", "sandbox"); string clientid = "<your client id>"; string secretid = "<your secret id>"; string accessToken = new OAuthTokenCredential(clientid, secretid, sdkConfig).GetAccessToken();

我以前使用RestSharp遇到未经授权的响应,然后找到了.我正在使用nuget包中的paypal sdk. 参考.

I previously encountered unauthorized response using RestSharp, then found this. I'm using paypal sdk from nuget package. Reference.

更多推荐

如何使用REST请求获取Paypal访问令牌

本文发布于:2023-10-29 09:44:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539370.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:令牌   如何使用   REST   Paypal

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!