我正在尝试使其正常运行 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访问令牌
发布评论