簡體   English   中英

如何通過搜索獲得Udemy Api的結果?

[英]How to get results from Udemy Api with search?

我想在我的網站上使用udemy api和api中的搜索字段。 Udemy給出了我的這個url:/api-2.0/courses/?search=mysql,當我使用時,我在結果中得到一個空數組。

但是,當我使用這個url:/api-2.0/courses/它工作正常,我得到1000行課程詳細信息..

請幫我解決搜索選項,如何使其工作?

<?php
echo "API testing is going on\n";


function callAPI($method, $url, $data){
   $curl = curl_init();

   switch ($method){
      case "POST":
         curl_setopt($curl, CURLOPT_POST, 1);
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
         break;
      case "PUT":
         curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
         if ($data)
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);                              
         break;
      default:
         if ($data)
            $url = sprintf("%s?%s", $url, http_build_query($data));
   }

   // OPTIONS:
   curl_setopt($curl, CURLOPT_URL, $url);
   curl_setopt($curl, CURLOPT_HTTPHEADER, array(   'Accept: 
application/json, text/plain, */*',
          'Content-Type: application/json;charset=utf-8',    
        'Authorization: xxx',
   ));
   curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

   // EXECUTE:
   $result = curl_exec($curl);
   if(!$result){die("Connection Failure");}
   curl_close($curl);
   return $result;
}

$URL="https://www.udemy.com/api-2.0/courses?search=mysql',auth= 
   ('xxclientidxx','xxclientsecretxx')'";

$get_data = callAPI('GET',$URL,false);
$response = json_decode($get_data, true);

$file_json=$response['results'];
$fp=fopen('results.json','w');
fwrite($fp,json_encode($response));
fclose($fp);

echo '<br>';


print_r($response['results']);

?>

如果您可以查看Udemy提供的API文檔,那將是一件好事。 Swagger API平台似乎可供他們使用。

請查看課程API的URL: https//www.udemy.com/developers/affiliate/methods/get-courses-list/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM