udemy api中的curl请求不起作用 [英] curl request in udemy api is not working
本文介绍了udemy api中的curl请求不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试通过请求udemy api来获得udemy课程目录,但是返回的只是 bool(false)
.
这是我的代码:
I'm trying to get the udemy course catalog by making a request to udemy api.But all its returning is bool(false)
.
Here is my code:
$ch = curl_init();
$headers = array(
'$udemy_client_id = xxx',
'$udemy_client_secret = xxxxx',
'Accept: application/json, text/plain, */*'
);
curl_setopt($ch, CURLOPT_URL, 'https://www.udemy.com/api-2.0/courses');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
curl_close($ch);
var_dump($data);
推荐答案
正确答案:
<?php
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);
?>
这篇关于udemy api中的curl请求不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文