Add curl HTTP Headers for new Udemy 2 API authentication in PHP

已悬赏 已发布的 Mar 31, 2015 货到付款
已悬赏 货到付款

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;

PHP 软件构架

项目ID: #7404540

关于项目

2个方案 远程项目 活跃的Mar 31, 2015

有2名威客正在参与此工作的竞标,均价$30/小时

r0mannn

HI I am really interested in project and ready to start as soon as you accept my bid. I will add authorization and base64 encryption to your script. I have many years of experience in php programming and have com 更多

$30 USD 在0天内
(72条评论)
5.0
gnouv

Hello, Could you share me a App ID and Secret Token for testing?   C 更多

$30 USD 在3天内
(9条评论)
2.9