简体   繁体   中英

How to GET promotional price using Udemy API?

I'm using the Udemy API in php to display the details of their courses on my website. But, I don't manage to get their promotional prices. I'm able to retrive all sort of details including the "original price" of each course but I don't find any field with the information of the promotional price. Can somebody help me please?

The code I'm using to get all information using course ID is the following:

function getcourse($id) {
    header('Content-Type: application/json');
    $url = "https://www.udemy.com/api-2.0/courses/$id?fields[course]=@all";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_URL,$url);
    $c_id = base64_encode('YOUR_CLIENT_ID');
    $c_sid = base64_encode('YOUR_CLIENT_SECRET');

    curl_setopt($ch,CURLOPT_HTTPHEADER,array('X-Udemy-Client-Id: '.$c_id.'','X-Udemy-Client-Secret: '.$c_sid.'',"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);

    curl_close($ch);

    $result = json_decode($result);
    return $result; 
}

This does not appear to be possible with their API, reading the model for the data they only list one item for "price",

https://www.udemy.com/developers/affiliate/models/course/

This leads me to suspect their is one of two possibilities here,
1. There is a bug in their API that does not return the promo price
2. This is a deliberate decision on their part to exclude this until the user clicks into the course at which point a "new" price is offered potentially based on if the user is logged into their Udemy account.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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