Hi i am trying to make a script that will let users see there friends twitter updates when they user my twitter ATM's in second life
I am wondering if someone can help
the is the code to get the users friends twitter xml
require("MagicParser.php");
function myRecordHandler($record)
{
$usertwittername = $record["NAME"];
$usertwitterstatus = $record["STATUS"];
}
$url = "twitter.com/statuses/friends/".$username.".xml";
MagicParser_parse("http://".$url,","myRecordHandler","xml|USERS/USER/");
and this is the part i need it to show in
if($resultArray['http_code'] == "0"){
$twitter_status="Error posting to Twitter.".$resultArray['http_code'];
}
else {
$twitter_status='Your message has been sent!';
}
return $twitter_status;
It needs to go in the $twitter_status i would like each status to have a new line and to limit to the last 10 posts, the script will not allow for new lines.
Thanks
Russell
I am wanting to show twitter.com/statuses/friends/russellharrower.xml
As you see it allows me to see what my friends are posting to twitter.
I would like show that feed (limit 5 posts) to the user who is using the ATM.
I am trying to show the users friends twitter status.
I would like to show the latest 5 twitter status from there friends
Hi Russell,
With regards to showing the status, the following code will display the first 5 friends and their last update:
<?php
require("MagicParser.php");
$c = 0;
function myRecordHandler($record)
{
global $c;
print "<p>";
print "<strong>".$record["SCREEN_NAME"]."</strong>: ";
print $record["STATUS/TEXT"];
print "</p>";
$c++;
return ($c==5);
}
$url = "http://twitter.com/statuses/friends/russellharrower.xml";
MagicParser_parse($url,"myRecordHandler","xml|USERS/USER/");
?>
Click here to see the output running on this server.
In terms of the code you posted, there was a typo in the way you were constructing the URL for use in the MagicParser_parse() call, the following line:
MagicParser_parse("http://".$url,","myRecordHandler","xml|USERS/USER/");
...should be:
MagicParser_parse("http://".$url,"myRecordHandler","xml|USERS/USER/");
(there was an extra ," in the code that breaks the syntax)
Hope this helps!
Cheers,
David.
Just wondering how i put the out put into $twitter_status =
Hi Russell,
An alternative to the above that simply puts the output into a variable called $twitter_status (without the HTML formatting, and a new line between each entry) would be:
<?php
require("MagicParser.php");
$twitter_status = "";
$c = 0;
function myRecordHandler($record)
{
global $c;
global $twitter_status;
$twitter_status .= $record["SCREEN_NAME"].": ";
$twitter_status .= $record["STATUS/TEXT"]."\n";
$c++;
return ($c==5);
}
$url = "http://twitter.com/statuses/friends/russellharrower.xml";
MagicParser_parse($url,"myRecordHandler","xml|USERS/USER/");
print $twitter_status;
?>
Remember that you won't see the newlines if viewing the above page in a browser unless you either set the output content-type to text/plain using this code at the top:
header("Content-Type: text/plain");
...or, you use the nl2br() function when printing $twitter_status, e.g.:
print nl2br($twitter_status);
Hope this helps!
Cheers,
David.
Hi Russell,
Could you describe the connection between the 2 sections in more details, it's clear what is provided to myRecordHandler for each of $username's friends, but I'm not sure exactly how you want to use that information in terms of $twitter_status.
New lines can normally be incorporated within a PHP code using the "\n"; but remember that new-lines are ignored by HTML; however they may still be meaningful externally..
Cheers,
David.