我試圖讓它工作https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/ 使用Java + Jersey應用程序。看起來我在POST params中錯過了一些東西。如何使用REST請求獲取貝寶訪問令牌
public String getPaypalToken() {
Client client = Client.create();
WebResource webResource = client.resource("https://api.sandbox.paypal.com/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 https://api.sandbox.paypal.com/v1/oauth2/token返回401未授權的響應狀態。
這curl命令行選項只是正常工作:
curl -X POST https://api.sandbox.paypal.com/v1/oauth2/token -H "Accept: application/json" -H "Accept-Language: en_US" -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" -d "grant_type=client_credentials"
任何建議將不勝感激。 J.
你能告訴如何進入android? –
嘗試此[文章](https://techtrendzy.wordpress.com/2013/10/10/get-an-access-token-for-rest-api/)或[來自PayPal的示例](https:// devtools -paypal.com/guide/pay_creditcard/java?interactive=ON&env=sandbox)您將需要PayPal Java Rest SDK作爲第二個鏈接,不完全是Android示例,但它是用Java編寫的......如果你還沒有在Android上工作,教我Android也許我們可以更快地解決你的問題:)) – juniordeveloper