Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you use the twitter api?

Tags:

twitter

I've just started trying to dive into the api. Right now I only know html and css as my background, and it seems the api uses a few languages I have no idea how to operate. I've made a working version of abraham's php-oauth. So I can log in and get some data back. But there seems to be no source saying do X to get Y result. I look at the API wiki and it just tells me what it can do, though not to do it. In short:

How do I look at the api wiki and turn a method into the code that tells twitter what i need? Thanks in advance, any help is appreciated. Sadly, there is no "idiots guide to twitter's api".

like image 316
dustinliamc Avatar asked Mar 21 '26 09:03

dustinliamc


1 Answers

Simple example:

function tweet($user,$pass,$app,$tweet)
{
    $url = 'http://'.$user.':'.$pass.'@twitter.com/statuses/update.xml';
    $post =  http_build_query(array ('source' => $app, 'status' => $tweet));
    $context = stream_context_create( array('http' => array('method' => 'POST', 'content' => $post)) );
    $connection = @fopen($url, 'rb', false, $context);
    if (!$connection) {
       return false;
    }
    fclose($connection);
    return true;
}

Usage Example:

tweet('username','password','tehuber','Hello World!');
like image 104
Srikar Doddi Avatar answered Mar 25 '26 01:03

Srikar Doddi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!