Add curl HTTP Headers for new Udemy 2 API authentication in PHP
$10-30 USD
Pagado a la entrega
Udemy has changed their API from 1.1 to 2 and added a step for authentication that has basically shut down my site pulling data using the 1.1 api. I found the example below and got it to work for the last several months but with the changes and now Udemy states that after April 20 they will not longer support 1.1 I need to get this fixed.
This is the url for the Udemy Developer API info. [url removed, login to view]
This is the new code that needs added to the script or a new script written.
The 1.1 only asked for the client_id and client_secret values but has now added on that there must be a base64 encoded HTTP Authorization. Udemy example:
curl --user {YOUR_CLIENT_ID}:{YOUR_CLIENT_SECRET} [url removed, login to view]
curl -H "Authorization: Basic {BASE64_ENCODED_CLIENT_ID:CLIENT_SECRET}" [url removed, login to view]
The code I am using now is this below. If the new Base64 part can be added then great but if I now need new code please let me know. Udemy is of little to no help with their api, affiliate program or much of anything so don't expect any help from them.
function get_data($url) {
$ch = curl_init();
$timeout = 5;
$udemy_client_id = 'xxxxx';
$udemy_client_secret = 'xxxxx';
HTTP Authorization
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-Udemy-Client-Id: '.$udemy_client_id,
'X-Udemy-Client-Secret: '.$udemy_client_secret
));
$data = curl_exec($ch);
curl_close($ch);
return $data;
}
$returned_content = get_data('[url removed, login to view]'.$id.'?fields[course]=@min,tagTitles,description,-images');
echo $returned_content;
Nº del proyecto: #7404540