开发者

Why does fopen produce varying files from calls to Twitter, when the file should be static?

开发者 https://www.devze.com 2023-01-22 16:08 出处:网络
I am trying to get a list of Twitter users using their API. When I query the API in my bro开发者_StackOverflow中文版wser (http://api.twitter.com/1/statuses/followers.xml?screen_name=atomictom), it ret

I am trying to get a list of Twitter users using their API. When I query the API in my bro开发者_StackOverflow中文版wser (http://api.twitter.com/1/statuses/followers.xml?screen_name=atomictom), it returns an XML doc with 100 users, as it should.

However, when performing the query from my php file:

$file=fopen("http://api.twitter.com/1/statuses/followers.xml?screen_name=atomictom", "r");
$xmlString=fread($file,13421772);
fclose($file);
echo $xmlString; 

it only returns 1, and sometimes 2 users. It actually varies when I refresh! Any ideas on why this would happen? I suspect a problem with fopen or fread. Unfortunately, in fread I cannot use filesize($file), as it is a resource and not a string.

Thank you so much for your help!


You could use file_get_contents() instead. There is no need to pass a file size arg to it, and it will work well if you have allow_url_fopen = On set in your php.ini file.

<?php
    echo file_get_contents("http://api.twitter.com/1/statuses/followers.xml?screen_name=atomictom");
?>


Are you sure your PHP code is logged in? It seems likely that when you try it from the browser, it's using your own logged in cookie, but your PHP code doesn't have access to that.

0

精彩评论

暂无评论...
验证码 换一张
取 消