Question

I am trying to get a list of Twitter users using their API. When I query the API in my browser (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!

Was it helpful?

Solution

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");
?>

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top