【发布时间】:2020-09-07 23:32:05
【问题描述】:
我正在尝试将 Udemy API 与 Stackoverflow 帖子中的正确答案一起使用:curl request in udemy api is not working
header('Content-Type: application/json');
$url = "https://www.udemy.com/api-2.0/courses";
// Initiate curl
$ch = curl_init();
// Disable SSL verification
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// Will return the response, if false it print the response
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Set the url
curl_setopt($ch, CURLOPT_URL,$url);
// Execute
curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Udemy-Client-Id: xxx','X-Udemy-Client-Secret: xxx',"Authorization: base64 encoded value of client-id:client-secret","Accept: application/json, text/plain, */*"));
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result=curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HEADER_OUT);
echo curl_getinfo($ch,CURLINFO_HTTP_CODE);
// Closing
curl_close($ch);
// Will dump a beauty json :3
echo $result = json_decode($result,true);
我添加了自己的客户端 ID 和机密 ID,并在 Udemy 网站上对其进行了测试,状态为 200。
我从上面的代码得到的错误是:403 Notice Array to string conversion.
谁能看到我错过了什么?
【问题讨论】:
标签: php curl oauth-2.0 php-curl