0

I used Dailymotion json API with PHP reference a lot code


If simple use browser surf the api url,the content "stream_h264_url" can copy used than played. but used PHP echo or print the json API copy "stream_h264_url", the result is blank page.

How to do that can solve this problem? Thanks.

======= Update: =======

probably this code can simple understand

<?php

?>

The result is blank page. If enable "header location".

See Example video http://www.dailymotion.com/video/k3xKoQWm7w1vDR8IxVM

I do not understand is, why use CodeRunner the result can play the video. Run the PHP file in web browser will not work.

Sorry, I give up.

OPUS
  • 73
  • 1
  • 6
  • Copying your code into here seems to work: http://www.compileonline.com/execute_php_online.php Could it be that to many requests in quick succession mean the request is ignored as I got a couple of warning for that. – Stuart Miller Aug 27 '14 at 16:24
  • Hi, I just update my post article, can see the new code. Thank you. – OPUS Aug 27 '14 at 18:57

2 Answers2

0

Is the problem that you aren't getting a response from curl, or that you just can't see any output?

Have you tried using var_dump(json_decode($content,true)); or echo $content; to ensure you are actually getting a response from Daily Motion?

You might also just be getting a White Screen of Death.

Update after video link posted: I wonder if the problem is that your curl request is being sent by the PHP server and Daily Motion grants the auth code to your server, but then you try to redirect a browser there using header: location, but the browser is not the same as your server, so the auth code is rejected by Daily Motion since it is not sent by the same requester as it granted the auth code to.

Community
  • 1
  • 1
AlphaCactus
  • 418
  • 3
  • 8
  • Hi, I just update my post article, can see the new code. Thank you. – OPUS Aug 27 '14 at 18:58
  • When I try to go to what should be in `$vdurl` which is [this](http://www.dailymotion.com/cdn/H264-320x240/video/xt27x1.mp4?auth=1409339775-2562-ehynlage-32d6e9984c196faa679ee243e70a5531) I get a 403 forbidden error. Which if I go to it directly (i.e. via `header( "location: ...");`) results in a blank page; the 403 error isn't shown. I see the 403 error using Firebug. I'm not familiar with Daily Motion so can't really debug beyond that. – AlphaCactus Aug 27 '14 at 19:25
  • Thank you for your response. You can see Example video http://www.dailymotion.com/video/k3xKoQWm7w1vDR8IxVM I do not understand is, why use CodeRunner the result can play the video. Run the PHP file in web browser will not work. – OPUS Aug 27 '14 at 19:47
0

i ran your code on my local machine the out put was

Array ( [stream_h264_sd_url] => http://www.dailymotion.com/cdn/H264-320x240/video/xt27x1.mp4?auth=1409329979-2562-powad7sw-c7d26f9df92ba4975d710020e793bd6d [stream_h264_hq_url] => [stream_h264_url] => http://www.dailymotion.com/cdn/H264-512x384/video/xt27x1.mp4?auth=1409329979-2562-s4iclgxy-6f7a4eed9658bc22bf4551c3991bb400 [stream_h264_hd_url] => ) 

make sure your curl and php are up to date

please also note i changed $session as $_SESSION is a global and also may cause issues

    $ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,"http://www.dailymotion.com/json/video/xt27x1?fields=stream_h264_sd_url,stream_h264_hq_url,stream_h264_url,stream_h264_hd_url");
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.9) Gecko/20071025 Firefox/2.0.0.9');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$content = curl_exec($ch); 
curl_close($ch); 
print_r(json_decode($content,true));
Zapps Ceo
  • 164
  • 13
  • Thank you for your response. But it doesn't work. Can see the original article,I just update. I upload php file in server: http://goo.gl/tcXWDc – OPUS Aug 27 '14 at 18:39