简体   繁体   English

ColdFusion Paypal REST API oAuth

[英]ColdFusion Paypal REST API oAuth

I am trying to implement the paypal REST API for an application in ColdFusion. 我正在尝试为ColdFusion中的应用程序实现paypal REST API。 I have my application set up in paypal so I have the client_id & secret key's. 我在PayPal中设置了我的应用程序,所以我有client_id和密钥。

https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/ https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/

This URL shows an example curl call that I am trying to reproduce in CF: 此URL显示我尝试在CF中重现的示例curl调用:

curl 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"

here is my CF call (modified the keys a little for my test account) 这是我的CF电话(为我的测试帐户修改了一点键)

<cfhttp method="post" url="https://api.sandbox.paypal.com/v1/oauth2/token"  result="test">
<cfhttpparam type="header" name="authorization" value="ASfK_BCZ54849na-kMSKvrKEk4WNDkoIikQlTfsI3nS-ghY1VTzH5q2pU:EC-7qhACEQ7XGjo2dU4gFPJDH3Et0KeMx0Z5Xmbf9PnhPE5diq-CO" >
<cfhttpparam type="header" name="content-type" value="application/x-www-form-urlencoded" >
<cfhttpparam type="formfield" name="grant_type" value="client_credentials" >

The response I receive is "invalid_client" - "invalid client credentials". 我收到的回复是“invalid_client” - “无效的客户端凭据”。 The docs state that the auhorization should be passed in the form "client_id:secret". 文档声明应该以“client_id:secret”的形式传递证据。 I have played around changing the names of my field's, tried passing it in the header and tried passing it as a formfield, all to no avail. 我玩过改变我的领域的名字,尝试在标题中传递它并尝试将其作为一个表格域传递,但都无济于事。 Best I can tell, paypal does not require a signature method and states it uses basic http auth. 最好的我可以告诉,paypal不需要签名方法,并声明它使用基本的http auth。

Can anyone see what I am missing here? 谁能看到我在这里想念的东西?

I'm not sure why your solution was not working for you, but not me. 我不确定为什么你的解决方案不适合你,但不是我。 It got me started, but I needed to tweak mine to get the request to go through. 它使我开始工作,但是我需要调整我的请求以完成请求。 Reverse engineering the PHP script I came up with this: 对PHP脚本进行反向工程,我想到了这一点:

<cfset clientid = "***************************"/>
<cfset secret = "***************************"/>

<cfhttp method="post" url="https://api.sandbox.paypal.com/v1/oauth2/token" result="local.test">
    <cfhttpparam type="header" name="Content_Type" value="application/json" >
    <cfhttpparam type="formfield" name="grant_type" value="client_credentials" >
    <cfhttpparam type="header" name="Authorization" value="Basic #ToBase64(clientid & ":" & secret)#">
</cfhttp>

I hope this saves someone else 3 hours of their Saturday. 我希望这可以节省别人三个星期的时间。 Now, I'm off to figure out the next steps. 现在,我要找出下一步。 If anyone is interested in wrapping this up into a full SDK like solution for the PayPal REST API let me know, I might be interested in collaborating. 如果有人有兴趣将其包装到类似PayPal REST API的完整SDK之类的解决方案中,请告诉我,我可能有兴趣进行协作。

我在内存中回答,但我似乎记得需要将内容类型设置为application / json,将其设置为application / x-www-form-urlencoded。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM