📜 ⬆️ ⬇️

PHP + Twitter

Twitter is now booming and there were reasons for that, there are good features in it that can be used in your projects.

On Habré there is a chip associated with it, if you enter your Twit account in your profile, the last message will be in your status - a trifle, but it's nice, you do not need to do the same thing twice.

The second example, which was the cause of my deepening into this question, is a project, we have not launched it yet, but as always we made a stub with the form for collecting addresses. So, so that it does not look sad and people can follow what is happening with the project, I created an account on Twitter and broadcast messages to this site in a convenient form. A person can go to the site and watch "what's new", and maybe use TWI, and I will need to enter the text only once. Moreover, people can easily ask a question, and I quickly find out about it.
')
In technical performance, everything turned out to be not difficult.

To begin, connect the class twitter.class.php . It has a set of standard functions:
- creating a tweet,
- reading your tape, friends or any particular user,
- a list of "followings" and "followers",
- messages
- something else.

Let's look at how to read your latest statuses:
require_once( "twitter.class.php" );
$t = new twitter();
$t->username= 'username' ; //
$t->password= 'pass' ; //

$res = $t->userTimeline(); // SimpleXMLElement.
if ($res=== false ){
echo "ERROR<hr/>" ;
echo "<pre>" ;
print_r($t->responseInfo);
echo "</pre>" ;
} else {
foreach ($res->status as $status){
echo $status->text . '<p/>' ;
}
}


* This source code was highlighted with Source Code Highlighter .


To find out what data is stored in the array of the returned class, you can display all of them, or you can look at the plug-in class from which .xml pages the information is parsed and examined.

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


All Articles