Hướng dẫn sử dụng Picasa Web Albums Data API để getlink picasaweb.Về cấu trúc API, ở bài trước mình đã có nói qua (CODE GETLINK PICASAWEB [VIEW-SOURCE])
https://picasaweb.google.com/data/entry/tiny/user/<!-- ID User -->/photoid/<!-- ID Photos -->
Mình sẽ hướng dẫn 1 dạng link sử dụng API này đơn giản nhất, các dạng khác các bạn có thể tìm hiểu sẽ ra.
Dạng link đơn giản đó là:
https://picasaweb.google.com/114988075669176415062/Update141019h?authkey=Gv1sRgCOSK3p-eqfCOwwE#6205497628839393650Với:
ID User là 114988075669176415062
ID Photo là 6205497628839393650
Giờ chỉ việc lắp vào link API trên thôi.
Code Getlink Picasaweb [API] bạn có thể tham khảo:
$link = 'https://picasaweb.google.com/114988075669176415062/Update141019h?authkey=Gv1sRgCOSK3p-eqfCOwwE#6205497628839393650';Code này mình để dữ liệu theo dạng mảng và bạn nào dùng Jwplayer thì gộp thành mảng sources là chiến được luôn.
preg_match('/https:\/\/picasaweb.google.com\/(.*)\/(.*)#(.*?)/U', $link, $id);
$s = explode('?', $id[2]);
if($s[1])
$view_source = curl('https://picasaweb.google.com/data/entry/tiny/user/'.$id[1].'/photoid/'.$id[3].'?'.$s[1].'');
else
$view_source = curl('https://picasaweb.google.com/data/entry/tiny/user/'.$id[1].'/photoid/'.$id[3].'');
preg_match_all("/<media:content url='(.*)' height='(.*)' width='(.*)' type='(.*)'\/>/U", $view_source, $data);
foreach($data[2] as $i => $quality)
{
if($quality > '300' and $quality <= '360' and !strpos($data[1][$i], 'gif'))
$lists[] = array('file' => $data[1][$i], 'type' => 'mp4', 'label' => '360p');
if($quality > '360' and $quality <= '720' and !strpos($data[1][$i], 'gif'))
$lists[] = array('file' => $data[1][$i], 'type' => 'mp4', 'label' => '720p');
if($quality > '720' and $quality <= '1080' and !strpos($data[1][$i], 'gif'))
$lists[] = array('file' => $data[1][$i], 'type' => 'mp4', 'label' => '1080p');
}
print_r($lists);
P/S: Code hoàn thiện đã có trong file download. Download
Không có nhiều thứ để nói về Picasaweb, vì nó quá phổ biến tại VN mà webmaster nào cũng biết.
Code dưới đây chưa phải là tối ưu và không thể lấy link chuyển từ Photos.
Bạn muốn lấy link dạng đó thì dùng:
https://picasaweb.google.com/data/entry/tiny/user/<!-- ID User -->/photoid/<!-- ID Photos -->để lấy link dạng chuyển từ Photos và nó cũng là cách tối ưu nhất với code getlink picasaweb.
Dưới đây là Code Getlink Picasaweb [View-Source]:
$link = 'https://picasaweb.google.com/114988075669176415062/Update141019h?authkey=Gv1sRgCOSK3p-eqfCOwwE#6205497628839393650';Code này mình để dữ liệu theo dạng mảng và bạn nào dùng Jwplayer thì gộp thành mảng sources là chiến được luôn.
$url = urldecode($link);
if(stristr($url, '#')) list($url, $id) = explode('#', $url);
$data = curl($url);
if($id) $gach = explode($id, $data);
$gach = explode('{"url":"', ($id)?$gach[7]:$data);
for($i=0; $i<4; $i++)
{
$data = urldecode(reset(explode('"', $gach[$i])));
if(strpos($data, 'redirector') || strpos($data, '=m18'))
$lists[] = array('file' => $data, 'type' => 'mp4', 'label' => '360p');
if(strpos($data, 'redirector') || strpos($data, '=m22'))
$lists[] = array('file' => $data, 'type' => 'mp4', 'label' => '720p');
if(strpos($data, 'redirector') || strpos($data, '=m32') || strpos($data, '=m37'))
$lists[] = array('file' => $data, 'type' => 'mp4', 'label' => '1080p');
}
print_r($lists);
P/S: Code hoàn thiện đã có trong file download. Download
Source: http://www.baosora.com/
0 Nhận xét