How do you use twitter api?

I just started trying to dive into the api. Right now I only know html and css as a background, and it seems that api uses several languages ​​that I don’t know how to work about. I created a working version of abraham php-oauth. Therefore, I can log in and get some data. But there seems to be no source saying that X should get a Y-result. I am looking at the API, and it just tells me what it can do, though not do it. Shortly speaking:

How to look at the api wiki and turn the method into code that tells Twitter what I need? Thanks in advance, any help is appreciated. Unfortunately, there is no "idiots guide for twitter api".

+3
source share
2 answers

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!');
0
source

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

For example, update user status :

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

HTTP method - POST (you can use cURL )

A necessary parameter for this method is "status", all others are optional.

I did not use the library you use, but I used twitter-async , for which there are pretty good examples , and I also used Zend

, twitter-async .

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

Source: https://habr.com/ru/post/1753012/


All Articles