PHP - 使用 YQL 选择特定条目
所以我使用 YQL 来获取 YouTube 用户的订阅者数量。
为此,我使用如下 URL 进行查询:
$query = 'https://query.yahooapis.com/v1/public/yql?q='.urlencode("SELECT * FROM xml WHERE url='http://gdata.youtube.com/feeds/api/users/{$id}'").'&format=json&callback=';
然后我解码响应并找到我正在寻找的数组条目,如下所示:
$response = json_decode($response, true);
$subscriber_count = $response['query']['results']['entry']['statistics']['subscriberCount'];
它工作正常,但我不喜欢我这样做的方式:) 我的意思是,有没有办法可以直接从上面的 $query
URL 获取 subscriberCount
值?我不需要整个 XML,只需要其中一个条目。
so I'm using YQL to get a youtube user's subscriber count.
to do this I'm making a query using a URL like this:
$query = 'https://query.yahooapis.com/v1/public/yql?q='.urlencode("SELECT * FROM xml WHERE url='http://gdata.youtube.com/feeds/api/users/{$id}'").'&format=json&callback=';
then I decode the response and find the array entry I'm looking for like this:
$response = json_decode($response, true);
$subscriber_count = $response['query']['results']['entry']['statistics']['subscriberCount'];
it works fine, except I don't like the way I'm doing this :)
I mean, is there a way I can get the subscriberCount
value directly from the $query
URL above? I don't need the entire XML, just that one entry.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以做的是将 YQL 返回的数据量限制为您真正感兴趣的数据,如下所示:
您仍然会在您感兴趣的数字周围有一些结构 XML/JSON 元素,但在至少它更少(见下文)。不确定这是否是您想要的?
What you could do is to limit the amount of data that is returned by YQL to the data you are really interested in by doing sth like this:
Still you would have some structural XML/JSON elements around the number that you are interested in but at least it is less (see below). Not sure if that is what you wanted?