我使用guzzle作为http客户端来消费paypal API
当我在curl的命令行中尝试paypal示例时,它确实有效
但是当我想用guzzle重现它时,我总是从paypal获得内部500错误..
这是来自官方文档的paypal curl示例(请点击此处https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/):
curl -v https://API.sandBox.paypal.com/v1/oauth2/token \ -H "Accept: application/Json" \ -H "Accept-Language: en_US" \ -u "clIEntID:clIEntSecret" \ -d "grant_type=clIEnt_credentials"
这是我的guzzle代码:
/** * Etape 1 récuperer un access token */$authResponse = $clIEnt->get("https://API.sandBox.paypal.com/v1/oauth2/token",[ 'auth' => [$apiclientID,$apiclientSecret,'basic'],'body' => ['grant_type' => 'clIEnt_credentials'],'headers' => [ 'Accept-Language' => 'en_US','Accept' => 'application/Json' ]]);echo $authResponse->getbody();
我尝试过auth basic,digest但到目前为止还没有工作.
感谢您的帮助!
解决方法 这是使用guzzlehttp$uri = 'https://API.sandBox.paypal.com/v1/oauth2/token';$clIEntID = \Your clIEnt_ID which you got on sign up;$secret = \Your secret which you got on sign up;$clIEnt = new \Guzzlehttp\ClIEnt();$response = $clIEnt->request('POST',$uri,[ 'headers' => [ 'Accept' => 'application/Json','Accept-Language' => 'en_US','Content-Type' => 'application/x-www-form-urlencoded',],'body' => 'grant_type=clIEnt_credentials','auth' => [$clIEntID,$secret,'basic'] ]);$data = Json_decode($response->getbody(),true);$access_token = $data['access_token'];总结
以上是内存溢出为你收集整理的转换paypal curl获取访问令牌请求进入guzzle全部内容,希望文章能够帮你解决转换paypal curl获取访问令牌请求进入guzzle所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)