0

I am trying to parse JSON data from an Ooyala URL but I'm having errors.

Sample Generated URL:

https://api.ooyala.com/v2/analytics/reports/account/performance/total/2015-01-01...2015-01-10?api_key=U3dms60g81_FPxszqQDbACnZsC_J.6so11&expires=1434366377&signature=NnE%2F6vsYOEJsrJ3yYEmO%2BXVXnr4d7ljDc8%2BvFNCkywo

Sample Response:

{"results":[{"id":"total","metrics":{"video":{"displays":90847,"uniq_displays":{"daily_uniqs":42819,"weekly_uniqs":32512,"monthly_uniqs":31838},"plays":27941,"uniq_plays":{"daily_uniqs":21075,"weekly_uniqs":17949,"monthly_uniqs":17679},"replays":1460,"uniq_replays":{"daily_uniqs":1101,"weekly_uniqs":1075,"monthly_uniqs":1075},"time_watched":4850762080,"playthrough_25":23086,"playthrough_50":21306,"playthrough_75":20013,"playthrough_100":16900,"player_loads":90688,"uniq_player_loads":{"daily_uniqs":42899,"weekly_uniqs":32565,"monthly_uniqs":31886},"video_bytes_downloaded":"This metric has been deprecated.","initial_plays":27597,"video_starts":27811,"uniq_video_starts":{"daily_uniqs":20992,"weekly_uniqs":17878,"monthly_uniqs":17609}}}}]}

Here's the error:

Warning: file_get_contents(<my URL here>): failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:\xampp\htdocs\Ooyala\GetURL.php on line 84

Fatal error: Maximum execution time of 30 seconds exceeded in C:\xampp\htdocs\Ooyala\GetURL.php on line 84

Code I'm trying to run:

$content = file_get_contents($url);
$json = json_decode($content, true);

ini_set('max_execution_time', 360);
foreach($json['results']['metrics']['video'] as $item)
{
    echo $item['playthrough_50'];
    echo '<br>';
    echo $item['video_starts'];
}

I have automatic configuration script in my internet options. Does it affect in using the file_get_contents() function?

Aldrin
  • 756
  • 6
  • 18
  • Does the URL opens in your browser just fine? – TiMESPLiNTER Jun 01 '15 at 10:52
  • Yeah it's fine when I'm redirecting to it. It shows the sample data I posted. – Aldrin Jun 01 '15 at 10:54
  • Without the URL we can't really help you out. – TiMESPLiNTER Jun 01 '15 at 10:55
  • I updated my post now, I added the code on how I generate the URL – Aldrin Jun 01 '15 at 11:04
  • Can you show us a concrete generated URL which fails in your case? So the `` would be interesting. – TiMESPLiNTER Jun 01 '15 at 11:04
  • https://api.ooyala.com/v2/analytics/reports/account/performance/total/2015-01-01...2015-01-10?api_key=U3dms60g81_FPxszqQDbACnZsC_J.6so11&expires=1434366377&signature=NnE%2F6vsYOEJsrJ3yYEmO%2BXVXnr4d7ljDc8%2BvFNCkywo – Aldrin Jun 01 '15 at 11:06
  • I can fetch this URL without any problems using `file_get_contents()`. Which PHP version are your running your code? There are some tricks to get HTTPS URLs working on the newest version. – TiMESPLiNTER Jun 01 '15 at 11:07
  • Does the link works fine with you? – Aldrin Jun 01 '15 at 11:08
  • I'm running PHP 5.6.9 – Aldrin Jun 01 '15 at 11:09
  • This answer should help you out: http://stackoverflow.com/a/26151993/1652031 – TiMESPLiNTER Jun 01 '15 at 11:10
  • Thank you so much for the response, I will try that one. – Aldrin Jun 01 '15 at 11:11
  • I added the verify_peer and verify_peer_name code but I still have the same error. > $opts=array( "ssl"=>array( "verify_peer"=>false, "verify_peer_name"=>false, ), ); $context = stream_context_create($opts); $content = file_get_contents($url, false, $context); $json = json_decode($content, true); ini_set('max_execution_time', 360); echo $json; – Aldrin Jun 01 '15 at 11:51
  • @TiMESPLiNTER I'm guessing i'ts because of my Automatic configuration Script in my Internet Options. Do you think it affects how the file_get_contents work? – Aldrin Jun 01 '15 at 15:44
  • Probably yes. Don't know what's inside this config script but it can of course affect the result you get from the URL. – TiMESPLiNTER Jun 02 '15 at 08:25

0 Answers0