【问题标题】:Issue with file_get_contents when count is more then 1当计数大于 1 时,file_get_contents 出现问题
【发布时间】:2012-03-13 02:56:55
【问题描述】:

所有, 我有以下代码:

$context = stream_context_create(array(
    'http' => array(
        'timeout' => 5      // Timeout in seconds
    )
));
$username = $options['account'];
$contents = file_get_contents( "https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count=1", 0, $context );

当我执行此代码时,它工作正常。但是,当我将内容更改为此时:

$how_many = $options['how_many'];
$contents = file_get_contents( "    
https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_many}", 0, $context );

我收到以下错误:

警告:file_get_contents(https://api.twitter.com/1/statuses/user_timeline.json?screen_name=Username&count=10) [function.file-get-contents]:打开流失败:没有错误

任何想法为什么它适用于一个而不适用于另一个。如果我将该 URL 复制并粘贴到浏览器中,也会返回结果。

【问题讨论】:

  • 检查 $context 是否真的存在,或者你错过了把它放在你的帖子上。
  • 您在第二个示例的第一行中拼错了$how_many
  • 您确定这与$how_man$how_many 不同吗?
  • 这是一个错字。我更新了我的问题。

标签: php file-get-contents


【解决方案1】:

不应该

how_many 是 $how_man?还是打错字了?

https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_man}", 0, $context );

【讨论】:

    【解决方案2】:

    我最终使用 cURL 来获取所有值,并且它有效。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-18
      • 2013-07-12
      • 1970-01-01
      • 1970-01-01
      • 2022-12-06
      • 2017-05-18
      相关资源
      最近更新 更多