1. Post #1
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    I'm working on importing tweets to my hompage at the moment, and I've got it all working except for a few things. Using twitterlibphp, I used getUserTimeline() to obtain my tweets, but by default it gets your latest 20.

    I want to cut this down to around 3 or 4 so as to not dominate my homepage with pointless twitter updates. I'm thinking it must be done cutting the foreach() loop short but I'm not sure how to do this.

    Here's my code, I'd greatly appreciate some pointers if you have any ideas:
    Code:
    <?php
    	// require library
    	require "twitter.lib.php";
    	
    	// twitter username / password
    	$username = "chrishdunne";
    	$password = "";
    	
    	// initializing the twitter class
    	$twitter = new Twitter($username, $password);
    	
    	// fetch my tweets
    	$xml = $twitter->getUserTimeline();
    	
    	$twitter_status = new SimpleXMLElement($xml);
    	foreach($twitter_status->status as $status) {
    		echo '				<li class="tweet"><a href="http://www.twitter.com/chrishdunne/status/' . $status->id . '">' . $status->text . '</a></li>' . "\n";
    		echo '				<li class="twitter_time">on ' . $status->created_at . '</li>' . "\n";
    	}
    	
    	// DO THIS NEXT:
    	//	* write tweets to file ?maybe
    	//	* control how many tweets appear on homepage using ?file ?array
    ?>

  2. Post #2
    HOLY FUCK EVERYONE HAS TITLES NOW
    AlphaGunman's Avatar
    January 2008
    4,243 Posts
    Idea: You could make a scroll bar.

  3. Post #3
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    Yeah I considered that, I really don't think it would compliment the layout at all though

  4. Post #4
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Code:
    $options["count"] = 3;
    $xml = $twitter->getUserTimeline($options);
    Something like that should do nicely.

    Edit: The Twitter API docs (http://apiwiki.twitter.com) are very useful here.
    Reply With Quote Edit / Delete Reply United Kingdom Show Events Useful Useful x 1 (list)

  5. Post #5
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    That didn't work. Where did you get the "max_id" option from? I searched for it on the apiwiki but nothing came up

  6. Post #6
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    I've never used twitterlibphp before, but that's from the official REST API page found here: http://apiwiki.twitter.com/Twitter-R...-user_timeline

    I'll try out twitterlibphp now.

    Edit: Oh, I'm an idiot. It's count not max_id, I was reading the wrong line.

  7. Post #7
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    count then?

    and don't worry, I was refreshing the page for ages wondering why my tweets weren't showing up, so I tried deleting the code you'd given me and put it back how it was and they still weren't showing up. then I realised I'd forgotten to put my password back in

    also, it still doesn't work even with this:
    Code:
    	// fetch my tweets / followers
    	$options["count"] = 3;
    	$xml = $twitter->getUserTimeline($options);

  8. Post #8
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Works fine with that code here, just edited your original source and it works. Post your full code as it stands please.

  9. Post #9
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    Code:
    <?php
    	// require library
    	require "twitter.lib.php";
    	
    	// twitter username / password
    	$username = "chrishdunne";
    	$password = "";
    	
    	// initializing the twitter class
    	$twitter = new Twitter($username, $password);
    	
    	// fetch my tweets / followers
    	$options["count"] = 3;
    	$xml = $twitter->getUserTimeline($options);
    	
    	$twitter_status = new SimpleXMLElement($xml);
    	foreach($twitter_status->status as $status) {
    		echo '				<li class="tweet"><a href="http://www.twitter.com/chrishdunne/status/' . $status->id . '">' . $status->text . '</a></li>' . "\n";
    		echo '				<li class="twitter_time">on ' . $status->created_at . '</li>' . "\n";
    	}
    	
    	// DO THIS NEXT:
    	//	* write tweets to file ?maybe
    	//	* control how many tweets appear on homepage using ?file ?array
    ?>

  10. Post #10
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Yup, that's working fine here? I'm running it CLI but that shouldn't make any difference.

  11. Post #11
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    mindfuck, going here produces nothing: http://suicidaltenants.net/
    but going directly to the page produces errors: http://suicidaltenants.net/index.php

    Code:
    SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 49: parser error : Entity 'rsaquo' not defined in /home/livehnet/public_html/includes/twitter.php on line 16

  12. Post #12
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    mindfuck, going here produces nothing: http://suicidaltenants.net/
    but going directly to the page produces errors: http://suicidaltenants.net/index.php

    Code:
    SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 49: parser error : Entity 'rsaquo' not defined in /home/livehnet/public_html/includes/twitter.php on line 16
    Neither is showing an error for me? Check you have cURL installed and that error reporting is enabled up to warning level.

  13. Post #13
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    Yeah I'm not sure why but the errors just stopped showing up? I must have cURL installed as the tweets were showing up fine before.

    I have a suspicion that maybe I used up all my API usage for the day

  14. Post #14
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Yeah I'm not sure why but the errors just stopped showing up? I must have cURL installed as the tweets were showing up fine before.

    I have a suspicion that maybe I used up all my API usage for the day
    Ah, quite possibly yeah, never thought of that. Probably best to cache the tweets in a MySQL DB or something.

  15. Post #15
    You'll have to speak up. I'm wearing a towel.
    omfgnex's Avatar
    January 2007
    762 Posts
    Hey hexxeh, just thought you might be interested to know that the script is working fine for me now. I think I probably did just max out my API usage.

    it seems kinda redundant caching the tweets in a database when they already exist in one. I've been looking through the API and it looks like there are ways of checking how much usage you have left and it outputs a percentage of some kind. i'll probably just put together an if statement and write it to a file if it's greater than like 10% or something, then just pull them from the file

    thanks for your help!

  16. Post #16
    Moderator Illuminati
    Hexxeh's Avatar
    June 2006
    5,091 Posts
    Hey hexxeh, just thought you might be interested to know that the script is working fine for me now. I think I probably did just max out my API usage.

    it seems kinda redundant caching the tweets in a database when they already exist in one. I've been looking through the API and it looks like there are ways of checking how much usage you have left and it outputs a percentage of some kind. i'll probably just put together an if statement and write it to a file if it's greater than like 10% or something, then just pull them from the file

    thanks for your help!
    You'd be better off just checking if there are any tweets you don't have stored locally, and download only the new ones. Good to hear it's working though.