views:

51

answers:

2

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".

A: 

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!');
CodeToGlory
"IMPORTANT: Basic authentication removal is going to occur on August 16, 2010"
SoftwareDev
A: 

Send POST or GET requests to the URL they tell you for the specified method, with the required parameters.

For example to update a user's status:

The URL is http://api.twitter.com/1/statuses/update.format (change "format" to either xml or json)

The HTTP method is POST ( you can use cURL )

The required parameter for this method is "status", all others are optional.

I haven't used the library you are using, but I have used twitter-async for which there are pretty good examples and I've also used Zend

Look at this excerpt taken from twitter-async's example for updating a user's status

 $status = $twitterObj->post('/statuses/update.json', array('status' => 'This a simple test from twitter-async at ' . date('m-d-Y h:i:s')));
SoftwareDev

related questions