skip to Main Content

I want to get list of private Dailymotion videos.

I am able to receive an access token with a private key. But then when I send Get request to retrieve the list of videos, I see the following "400 Bad Request: malformed Host header".

<?php
$url = "https://partner.api.dailymotion.com/oauth/v1/token";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
   "Host: partner.api.dailymotion.com",
   "Content-Type: application/x-www-form-urlencoded",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$data = "grant_type=client_credentials&client_id=xxx&client_secret=xxx&scope=manage_videos";
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$resp = curl_exec($curl);
curl_close($curl);
$data = json_decode($resp, true);
$access_token = $data['access_token'];
$url = "https://partner.api.dailymotion.com/user/xxx/videos?fields=id&limit=30&private=true";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = array(
    "Host: partner.api.dailymotion.com/rest",
);
$auth = "Authorization: Bearer " . $access_token;
$headers[1] = $auth;
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$resp = curl_exec($curl);
curl_close($curl);
//var_dump($resp);
?>

2

Answers


  1. Chosen as BEST ANSWER

    The key used is actually Public API when the code is using Private API endpoint. To access private data with public API key, access token will need to be generated with username and password along with the key and secret.

    <?php
    //Perform authentication
    $url = "https://api.dailymotion.com/oauth/token";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_POST, true);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = array( 
    "Content-Type: application/x-www-form-urlencoded", 
    ); 
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); 
    $data = "grant_type=password&client_id=xxx&client_secret=xxx&username=xxx&password=xxx&scope=email,feed,manage_analytics,manage_app_connections,manage_applications,manage_claim_rules,manage_domains,manage_features,manage_history,manage_likes,manage_player,manage_players,manage_playlists,manage_records,manage_subscriptions,manage_subtitles,manage_user_settings,manage_videos,read_insights,userinfo";
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
    $resp = curl_exec($curl);
    curl_close($curl);
    $data = json_decode($resp, true);
    
    //Retrieve an access token
    $access_token = $data['access_token'];
    
    //Get the list of video IDs
    $url = "https://api.dailymotion.com/user/xxx/videos?fields=id&limit=30&private=true";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    $headers = array(
    
    );
    $auth = "Authorization: Bearer " . $access_token;
    $headers[0] = $auth;
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $resp = curl_exec($curl);
    curl_close($curl);
    $data = json_decode($resp, true);
    $pubids = array_column($data['list'], 'id');
    
    //Get the list of private ids
    $privids = array(
    
    );
    foreach ($pubids as $pubid):
    $url = "https://api.dailymotion.com/video/" . $pubid . "?fields=private_id";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_URL, $url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    $resp = curl_exec($curl);
    $data = json_decode($resp, true);
    $privid = $data['private_id'];
    curl_close($curl);
    array_push($privids, $privid);
    endforeach;
    ?>
    

  2. You can try the following

    $url = "https://api.dailymotion.com/user/xxx/videosfields=id&limit=30&private=true";
    $curl = curl_init($url);
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    
    $headers = array(
        "Authorization: Bearer " . $access_token,
        "Content-Type: application/json"
    );
    
    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
    
    $resp = curl_exec($curl);
    curl_close($curl);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search