Php 使用youtube api显示subscriberCount-xmlns解析

Php 使用youtube api显示subscriberCount-xmlns解析,php,xml,wordpress,Php,Xml,Wordpress,全部 我想用它的api显示youtube订户。 但无法使用php获取subscriberCount 这是api链接: 结果 <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:

全部

我想用它的api显示youtube订户。 但无法使用php获取subscriberCount

这是api链接

结果

    <?xml version='1.0' encoding='UTF-8'?><entry xmlns='http://www.w3.org/2005/Atom' xmlns:media='http://search.yahoo.com/mrss/' xmlns:gd='http://schemas.google.com/g/2005' xmlns:yt='http://gdata.youtube.com/schemas/2007'><id>http://gdata.youtube.com/feeds/api/users/worshipuk</id><published>2009-05-22T10:57:17.000-07:00</published><updated>2011-12-07T19:45:47.000-08:00</updated><category scheme='http://schemas.google.com/g/2005#kind' term='http://gdata.youtube.com/schemas/2007#userProfile'/><category scheme='http://gdata.youtube.com/schemas/2007/channeltypes.cat' term='Musician'/><title type='text'>worshipuk</title><content type='text'>'Worship make brilliantly moody, haunting music. Soaring vocals and tense, synth-laden atmospherics combine with subtle rhythmic complexities, creating very mood driven, dark and broody sounds with bursts of light. A new project, the band spent a month of writing and recording (self-producing) at a small residential studio in Norway. A bright, if slightly dark future, awaits.' - RockFeedback

http://www.facebook.com/worshipuk
http://www.myspace.com/worshipuk
http://www.twitter.com/worshipuk</content><link rel='alternate' type='text/html' href='http://www.youtube.com/profile?user=worshipuk'/><link rel='http://gdata.youtube.com/schemas/2007#featured-video' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/videos/cWZPWXWpa4I'/><link rel='related' type='text/html' href='http://www.worshipuk.com'/><link rel='self' type='application/atom+xml' href='http://gdata.youtube.com/feeds/api/users/worshipuk'/><author><name>worshipuk</name><uri>http://gdata.youtube.com/feeds/api/users/worshipuk</uri></author><yt:age>110</yt:age><yt:description>'Worship make brilliantly moody, haunting music. Soaring vocals and tense, synth-laden atmospherics combine with subtle rhythmic complexities, creating very mood driven, dark and broody sounds with bursts of light. A new project, the band spent a month of writing and recording (self-producing) at a small residential studio in Norway. A bright, if slightly dark future, awaits.' - RockFeedback

http://www.facebook.com/worshipuk
http://www.myspace.com/worshipuk
http://www.twitter.com/worshipuk</yt:description><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.favorites' href='http://gdata.youtube.com/feeds/api/users/worshipuk/favorites' countHint='2'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.contacts' href='http://gdata.youtube.com/feeds/api/users/worshipuk/contacts' countHint='0'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.inbox' href='http://gdata.youtube.com/feeds/api/users/worshipuk/inbox'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.playlists' href='http://gdata.youtube.com/feeds/api/users/worshipuk/playlists'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.subscriptions' href='http://gdata.youtube.com/feeds/api/users/worshipuk/subscriptions' countHint='0'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.uploads' href='http://gdata.youtube.com/feeds/api/users/worshipuk/uploads' countHint='3'/><gd:feedLink rel='http://gdata.youtube.com/schemas/2007#user.newsubscriptionvideos' href='http://gdata.youtube.com/feeds/api/users/worshipuk/newsubscriptionvideos'/><yt:firstName>Worship</yt:firstName><yt:gender>m</yt:gender><yt:location>GB</yt:location><yt:statistics lastWebAccess='2011-11-10T03:33:40.000-08:00' subscriberCount='62' videoWatchCount='0' viewCount='1653' totalUploadViews='25141'/><media:thumbnail url='http://i1.ytimg.com/i/lwjfgavcsk4RwuI3yf0eJA/1.jpg?v=c8ce1f'/><yt:username>worshipuk</yt:username></entry>
http://gdata.youtube.com/feeds/api/users/worshipuk2009-05-22T10:57:17.000-07:002011-12-07T19:45:47.000-08:00Attembeuk的崇拜会制造出非常忧郁、令人难以忘怀的音乐。高亢的人声和紧张的、充满合成器的气氛与微妙的节奏复杂结合在一起,通过光线的爆发创造出非常情绪化、黑暗和忧郁的声音。作为一个新项目,乐队花了一个月的时间在挪威的一个小型住宅工作室进行创作和录音(自拍)。一个光明的,尽管有点黑暗的未来,等待着你
http://www.facebook.com/worshipuk
http://www.myspace.com/worshipuk
http://www.twitter.com/worshipukworshipukhttp://gdata.youtube.com/feeds/api/users/worshipuk110“崇拜会制造出令人心神不宁的音乐。高亢的人声和紧张的、充满合成器的气氛与微妙的节奏复杂结合在一起,通过光线的爆发创造出非常情绪化、黑暗和忧郁的声音。作为一个新项目,乐队花了一个月的时间在挪威的一个小型住宅工作室进行创作和录音(自拍)。一个光明的,尽管有点黑暗的未来,等待着你
http://www.facebook.com/worshipuk
http://www.myspace.com/worshipuk
http://www.twitter.com/worshipukWorshipmGBworshipuk
我使用这个php代码来解析这个xml结果,以获得subscriberCount:62

<?php
$det = simplexml_load_file('http://gdata.youtube.com/feeds/api/users/worshipuk');

echo "<pre>";
print_r($det);
?>


如何使用php使用此api获取subscriberCount?

我也有同样的问题。使用下面的代码,我相信你会得到你的订阅数

function get_yt_subs($username) { 

$xmlData = file_get_contents('http://gdata.youtube.com/feeds/api/users/' . strtolower($username)); 
$xmlData = str_replace('yt:', 'yt', $xmlData); 

$xml = new SimpleXMLElement($xmlData); 

$subs = $xml->ytstatistics['subscriberCount']; 

return($subs); 

}
$name='shoveruk'; $url='1http://gdata.youtube.com/feeds/api/users/'. urlencode($name)。“?alt=json”; $json=@file_get_contents($url);//调皮的@-操作员,使用正确的错误处理 $data=json_decode($json,TRUE); $count=(int)$data['entry']['yt$statistics']['subscriberCount']; echo$count;
您还可以使用此功能:

用法示例:

PHP代码: 获得一个小游戏('GameTuts')
返回:


16733

问题在哪里?问题是什么?@awaisgarni如何使用php获取此api的subscriberCount?请输入打印($det)的结果
function get_yt_subs($username) { 

$xmlData = file_get_contents('http://gdata.youtube.com/feeds/api/users/' . strtolower($username)); 
$xmlData = str_replace('yt:', 'yt', $xmlData); 

$xml = new SimpleXMLElement($xmlData); 

$subs = $xml->ytstatistics['subscriberCount']; 

return($subs); 

}