Twitter API PHP script error

Posted by bardockyo on Stack Overflow See other posts from Stack Overflow or by bardockyo
Published on 2012-11-15T22:58:10Z Indexed on 2012/11/15 22:59 UTC
Read the original article Hit count: 126

Filed under:
|
|
|

I am having issues with my php script that I am using for gathering a users followers by accessing the twitter API. The script works fine for a user that has < 5000 followers but I tried adjusting the script using cursors to collect the complete set of users. Here is my script:

<?php
$cursor = -1;


$file = fopen ('ids.csv', 'w+');
fwrite($file, "User id\n\r");

for ($i = 0; $i <= 1; $i++)
{
 $xml = getFollowers($cursor);

 foreach ($xml->ids->id as $id) 
 {
    fwrite($file, $id . ", ");
    fwrite($file, "\n");
 }

 $cursor = $xml->next_cursor;
 }

 function getFollowers ($cursor)
 {
    $xmldata = 'https://api.twitter.com/1/followers/ids.xml?cursor='.$cursor.'&screen_name=microsoft';
    $open = fopen($xmldata, 'r');
    $content = stream_get_contents($open);
    fclose($open);
    $xml = simplexml_load_file($xmldata);

    return $xml;
}

 ?>

I am getting an error

Warning: fopen("https://api.twitter.com/1/followers/ids.xml?cursor=-1&screen_name=microsoft") failed to open stream HTTP request failed bad request warning: stream_get_contents() expects parameter 1 to be resource, boolean given.

Any ideas?

© Stack Overflow or respective owner

Related posts about php

Related posts about Xml