Quantcast
Channel: Coffeewithcode.com
Viewing all articles
Browse latest Browse all 40

Php code for twitter interaction

$
0
0

Let’s take a look how php code interacts with twitter.

1.) How to get number of  twitter followers.

  1. fnction get_followers($twitter_id){
  2.     $xml=file_get_contents('http://twitter.com/users/show.xml?screen_name='.$twitter_id);
  3.     if (preg_match('/followers_count>(.*)</',$xml,$match)!=0) {
  4.         $tw['count'] = $match[1];
  5.     }
  6.  
  7.     return $tw['count'];
  8. }

Now call this function with this code

  1. $followers = get_followers(‘vimalm4u’);
  2. echo “You have”.$followers.”followers!;

2.) Get number of retweets for a specific page.

       Function will get the number of  retweets of the url passed as a parameter

  1. function rtweetCount($url) {
  2.    $content = file_get_contents("http://api.tweetmeme.com/url_info?url=".$url);
  3.    $element = new SimpleXmlElement($content);
  4.    $retweets = $element->story->url_count;
  5.    if($retweets){
  6.        return $retweets;
  7.    } else {
  8.        return 0;
  9.    }
  10. }
  11.  
  12. echo rtweetCount('http://www.coffeewithcode.com');

3) Shorten urls for Twitter

      As we know, we can’t tweets messages which are longer than 140 characters. To avoid this problem, you have to use an url shortener.

 

  1. function getTinyUrl($url) {
  2.    return file_get_contents("http://tinyurl.com/api-create.php?url=".$url);
  3. }

Viewing all articles
Browse latest Browse all 40

Trending Articles