全部,我有以下代码:
$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)[函数.file获取内容]:无法打开流:无错误
为什么它对其中一个有效而对另一个无效。如果我将该URL复制并粘贴到浏览器中,结果也会返回。
不应该
怎么可能是$how_man?还是打字错误?
https://api.twitter.com/1/statuses/user_timeline.json?screen_name={$username}&count={$how_man}", 0, $context );
我最终使用cURL来获取所有值,并且成功了。