I want to get the private video ids of private dailymotion playlist with public API key. I try the following:
<?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/playlist/xxx/videos?fields=private_id%2Cprivate=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);
//$ids = array_column($data['list'], 'private_id');
//print_r($ids);
var_dump($data);
?>
I get the following, though there are private videos in that private playlist:
array(6) { ["page"]=> int(1) ["limit"]=> int(10) ["explicit"]=> bool(false) ["total"]=> int(0) ["has_more"]=> bool(false) ["list"]=> array(0) { } }
<?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 playlist page number
$limit = 100;
$url = "https://api.dailymotion.com/collection/xxx?fields=videos_total";
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = [];
$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);
$videostotal = $data['videos_total'];
$pagetotal = ceil($videostotal / $limit);
//Get the list of video IDs of playlist
$ids = [];
for ($i = 1; $i <= $pagetotal; $i++) {
$url = "https://api.dailymotion.com/collection/xxx/videos?fields=private_id&private=true&limit=" . $limit . "&page=" . $i;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$headers = [];
$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);
$ids = array_merge($ids,array_column($data['list'], 'private_id'));
}
?>