ท่านใดรัน Code นี่ได้บ้างครับ (Get JSON จาก Dailymotion)

เริ่มโดย dekmv, 15 พฤษภาคม 2013, 15:25:38

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

dekmv


<?php
 $data 
file_get_contents('https://api.dailymotion.com/video/xjfn0s?fields=thumbnail_small_url');
 
$data json_decode($data);
 
print_r($data);
?>



ผมรันแล้ว

Warning: file_get_contents(https://api.dailymotion.com/video/xjfn0s?fields=thumbnail_small_url) [function.file-get-contents]: failed to open stream: No error in C:\AppServ\www\test\index.php on line 13

เกิดจากอะไร แก้ยังไงครับ ?  :P

@@@

server ไม่ได้เปิดสิทธิ์ในการ เปิดไฟล์จาก server อื่นครับ
ลองใช้เป็น CURL ดูครับ


function _curl($url){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_FAILONERROR, 1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 3);
   curl_setopt($ch, CURLOPT_HTTPGET, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
   $result = curl_exec($ch);
   curl_close($ch);
   return $result;
}
$result=_curl('https://api.dailymotion.com/video/xjfn0s?fields=thumbnail_small_url');
รับซื้อเว็บ 100uip ต่อวันขึ้นไป [direct=http://www.rommit.com/forex]EA Forex[/direct]

dekmv

อ้างถึงจาก: @@@ ใน 15 พฤษภาคม 2013, 15:51:29
server ไม่ได้เปิดสิทธิ์ในการ เปิดไฟล์จาก server อื่นครับ
ลองใช้เป็น CURL ดูครับ


function _curl($url){
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url);
   curl_setopt($ch, CURLOPT_FAILONERROR, 1);
   curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
   curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
   curl_setopt($ch, CURLOPT_TIMEOUT, 3);
   curl_setopt($ch, CURLOPT_HTTPGET, 1);
   curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5');
   $result = curl_exec($ch);
   curl_close($ch);
   return $result;
}
$result=_curl('https://api.dailymotion.com/video/xjfn0s?fields=thumbnail_small_url');


ขอบคุณครับ ^^

dekmv

ข้อมูลออกมาแล้ว แต่แกะไม่ออก !

stdClass Object
(
    [description] =>
    [duration] => 243
    [id] => xynlet
    [owner] => x1a54fu
    [owner.screenname] => Debiles
    [owner.url] => http://www.dailymotion.com/Debiles
    [tags] => Array
        (
           

forsiam

ลอง

foreach ( $data as $a ){
$video['title'] = $a->title;
$video['description'] = $a->description;
$video['code'] = $a->id;
$video['image_mini'] = $a->thumbnail_medium_url;
$video['image_hd'] = $a->thumbnail_large_url;
$video['uploader'] = $a->owner.url;
$video['duration'] = $a->duration;
$video['keyword'] = $a->tags;

}