[英]What format and content-type is the body of a paypal rest access token call?
I am using Java with Jersey 2.0 client to make a REST call to the paypal REST API. 我正在将Java与Jersey 2.0客户端一起使用,以对Paypal REST API进行REST调用。 According to the API doc, I should be making a post to: https://api.sandbox.paypal.com/v1/oauth2/token with the Accept: application/json and Accept-Language: en_US. 根据API文档,我应该发布一个帖子到: https ://api.sandbox.paypal.com/v1/oauth2/token,并带有Accept:application / json和Accept-Language:en_US。 It also indicates that I should pass in the body grant_type=client_credentials. 它还表明我应该传递主体Grant_type = client_credentials。 I do all this but I keep getting a 406 or 415. What I can't figure out is what the Content-Type of the post call should be? 我做了所有这些,但是仍然收到406或415。我不知道发帖的Content-Type应该是什么? I've tried text/plain, text/html, application/json, form-url-encoded.. nothing seems to get me a token back. 我已经尝试过text / plain,text / html,application / json,form-url-encoded ..似乎没有什么可以让我获得令牌的。 Not sure why their API doc writer didn't include the Content-Type and format of the payload in the documentation. 不确定为什么他们的API文档编写者没有在文档中包括有效内容的Content-Type和格式。 Anyone know what the Content-Type should be for the body of the post? 任何人都知道帖子正文的Content-Type应该是什么?
I'd like to add that when I do any Content-Type other than form-url-encoded, I get back 415, which means mediatype not accepted, however when I pass in anything using form-url-encoded, I get back the 406, which basically tells me the body is not acceptable. 我想补充一点,当我执行除form-url-encoded之外的任何Content-Type时,我会返回415,这表示未接受mediatype,但是当我使用form-url-encoded传递任何内容时,我会返回406,这基本上告诉我身体是不可接受的。
Thanks. 谢谢。
Thanks for bringing up the question. 感谢您提出问题。
There was a recent change in the /token call and requests for an access token need to have the content-type
set as application/x-www-form-urlencoded
. / token调用最近发生了变化,访问令牌的请求需要将content-type
设置为application/x-www-form-urlencoded
。 This is done by default in cURL calls. 默认情况下,这是在cURL调用中完成的。
Updated docs that include a note about this will be going out very soon. 包含有关此注释的更新文档将很快发布。
Inbound the OAuth 2 endpoint only accepts "application/x-www-form-urlencoded" or it will throw a 415, the payload then needs to be properly url encoded. OAuth 2端点的入站仅接受“ application / x-www-form-urlencoded”,否则将抛出415,然后需要对有效负载进行适当的url编码。 Likewise the accepts header needs to contain "application/json", or the service will throw a 406. 同样,accepts标头需要包含“ application / json”,否则服务将抛出406。
For example: 例如:
Headers: Authorization: Basic [base64 encoded] Content-Type: application/x-www-form-urlencoded Accepts: application/json 标头:授权:基本[base64编码]内容类型:application / x-www-form-urlencoded接受:application / json
Payload sample: grant_type=client_credentials&response_type=token 有效负载样本:grant_type = client_credentials&response_type = token
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.