views:

57

answers:

4

Hi,

I want to embed a specific tweet on my page e.g http://twitter.com/myusername/status/123465678 I would also like to be able to show the latest of my tweets which have a specific tag.

I tried to do this with Twitter API CodeIgniter Library myself but I need to register my application with Oauth. This seems like overkill for embeding one tweet on a page.

I would prefer to do this with PHP but will probably need to settle for a jquery version. Can anyone point me towards a script that can do this?

thanks

A: 

I think you can consume a public feed without using Oauth. I haven't worked with it in a while, but this code worked for me at one time:

$url = "http://twitter.com/yourtwittername";
$h = curl_init($url);
curl_setopt($h,CURLOPT_POST,TRUE);
curl_setopt($h,CURLOPT_POSTFIELDS,$params);
curl_setopt($h,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($h,CURLOPT_VERBOSE,1);
curl_setopt($h,CURLOPT_HTTPHEADER,array('Expect:'));
$response = json_decode(curl_exec($h));
$results = curl_getinfo($h); # to check for http response, etc.
curl_close($h);
// additional processing on response ...
bogeymin
A: 

You could use pure javascript, see http://twitter.com/goodies/widget_profile for a twitter profile widget. Then customize it to show only one tweet (or look at their js code :D).

elektronikLexikon
A: 

I did this once using curl, you may have to enable it first in your php.ini

here is a class that could probably do the job for you

<?php
class TwitterGrub{
    private $user;
    private $password;

    function __construct($user, $password) {
        $this->user = $user;
        $this->password = $password;
    }

    function setUser($user) {
        $this->user = $user;
    }

    // same for password


    function twitterCapture() {  


       $ch = curl_init("https://twitter.com/statuses/user_timeline.xml");  
       curl_setopt($ch, CURLOPT_HEADER, 1);  
       curl_setopt($ch,CURLOPT_TIMEOUT, 30);  
       curl_setopt($ch,CURLOPT_USERPWD,$this->user . ":" . $this->password);  
       curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);  
       curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);  
       curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);  
       $result=curl_exec ($ch);  
       $data = strstr($result, '<?');  

       $xml = new SimpleXMLElement($data);  

      return $xml;  
}   


function twitterDisplay($twitNum = 2){
    $xml = $this->twitterCapture(); 

    for($i= 0; $i<$twitNum; $i++){ 
        echo   $xml->status[$i]->text;    
    }
}
rabidmachine9
SimpleXMLElement Object ( [error] => Basic authentication is not supported );
gemmes
"Basic authentication is not supported" This is the error I was getting before with the CodeIgniter Twitter API. I am guessing you cannot do anything without oAuth now.
gemmes
seems like you are right...please post the solution if you find it
rabidmachine9