【问题标题】:Is there a limit to wp_remote_get and/or simplexml_load_string from Vimeo?Vimeo 中的 wp_remote_get 和/或 simplexml_load_string 是否有限制?
【发布时间】:2013-05-21 11:24:51
【问题描述】:

我知道 *wp_remote_get* 是一个 WordPress 函数,我应该将它发布在 wordpress.stackexchange 中,但是,我几乎可以肯定我的问题更多地在于一般的 PHP 方面。

问题:我需要检索在相册中找到的所有 Vimeo 视频,但我只有 20 个。

方法:

$vmg_feed_url = 'http://vimeo.com/api/v2/';
$vmg_user = '2212323';
if($vmg_type == 'user'){ /** just an input variable checking whether the function should search for user or for album. in our case, it searches for album **/
    $vmg_type_url = '';
} else {
    $vmg_type_url = $vmg_type . '/';
}
$vmg_videos_url = $vmg_feed_url . $vmg_type_url . $vmg_user . '/videos.xml';
$videos_result = wp_remote_get($vmg_videos_url);
$vmg_videos = simplexml_load_string($videos_result['body']);

生成的 XML 是 http://vimeo.com/api/v2/album/2212323/videos.xml - 如您所见,我只检索 20 个视频。

问题:我错过了什么吗?是否有一个函数/变量可以限制我可以检索的视频数量?我知道 wp_remote_get 为我提供了这些属性 (from the WordPress Codex):

$url (字符串)(必需)通用资源定位器 (URL)。 - 默认:无

$args (数组)(可选) - 默认:方法:GET,超时:5,重定向:5,httpversion:1.0,阻塞:true,标头:array(),正文:null,cookie:array()

非常感谢任何帮助。如果我忘记了任何细节,请告诉我!

【问题讨论】:

    标签: php xml api


    【解决方案1】:

    你的问题不在 wordpress 或 PHP 中。这是 API 限制:

    http://developer.vimeo.com/apis/simple

    简单的 API 响应包括每页最多 20 个项。

    您可以通过在下一个请求中添加?page 参数来获得更多。

    【讨论】:

    • 嘿,谢谢!我错过了。我刚刚在 Vimeo 上找到了 Simple API 页面,现在想知道如何使用页面参数(带有回调?)来检索 60 个视频?我知道 myurl?page=2 会显示第二页,但是如何在上面的代码中实现它,以便获取第 1、2 和 3 页并检索 60 个视频?谢谢!
    • 您必须提出三个单独的请求并合并结果。这是一个非常简单的操作,所以请先尝试自己做。
    • 知道了,我认为请求 URL 中可能有一个简单的附加变量。再次感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    相关资源
    最近更新 更多