Posterous Joins Twitter. Customers Join WordPress

Even though there’s no reblog feature on self-hosted WordPress blogs, I absolutely have to reblog this: Reblogged from WordPress.com News

Posterous Import to WordPress.com

It’s been just over two years since we first launched our Posterous importer and I never could have predicted how the blogging space would evolve so quickly in that time. As you may have seen in the news today, the Posterous team is joining Twitter, which we know will be exciting for our friends at Twitter and well-earned for Posterous co-founder Sachin Agarwal.

And this is even more exciting:

We’ve had an over 250% spike in the number of imports the past few hours, so it seems timely to recap how the importer works.

A 250% spike! And that’s not counting self-hosted blogs, incredible, and quite obvious at the same time. The Posterous importer works well for both WordPress.com hosted blogs, as well as self-hosted blogs via the plugin. So what are you waiting for? If you ever thought of switching from Posterous to WordPress, now’s the best time to do it.

Tumblr, hope you’re ready, cause you’re next ;)

An Actual Retweet Button for Jetpack & Sharedaddy

I was thinking about this for quite some time now — an actual retweet button for WordPress, and I wonder why Twitter hasn’t provided one yet, it’s so obvious!

Sharedaddy Retweet Button

Yes, the tweet button is doing a great job these days, but let’s admit, that we content publishers enjoy retweets more than regular tweets to our articles, because:

  • They show your name and your Twitter avatar along with the original message, so when others see your tweet retweeted, there’s a better chance they’ll follow you.
  • They instantly show up in your Interactions and increase the retweet count, so you can always see who’s tweeting your posts, without having to use Twitter’s search.
  • They give you a better chance to get a Top Tweet, thus providing even more exposure.

Continue reading

Announcing the Twitter Embed Plugin for WordPress

Hey there! I just released a brand new WordPress plugin called Twitter Embed. It supports several ways of embedding tweets into your WordPress posts and pages. The new (new-new) Twitter interface has introduced a new link on tweets called “Embed this Tweet” which allows embedding through HTML code, shortcode or link.

Twitter Embed

This plugin implements all of those ways. It will even reverse an embed HTML into a shortcode if the user doesn’t have privileges to post unfiltered HTML. It caches the API responses from Twitter.com for better performance and well, it’s as simple as it looks and sounds, doesn’t require any configuration and works out of the box, right after activation.

Download it from the WordPress.org Plugins Directory, give it a spin and let me know if it works for you. Cheers and Happy New Year!

Foller.me is Back Online, and now Filled with WordPress Goodness!

Twitter Analytics

Foller.me has got a new home, again! I’ve spent a few days working on a complete overhaul since Google App Engine’s pricing model has changed, which made the app consume over $5/week. It’s not big money but I thought I’d rather host the app next to my own blog for free ;)

The (yet another) new version of Foller.me is powered by WordPress, so if you’ve got friends who still think WordPress is for blogs only, share this with them. Instead of inventing a new user interface I went with Bootstrap and was able to prototype the whole thing really, really fast. I removed the followers geography part for now, I’ll need to find a better way to lay that out and make it actually function. Meanwhile you can enjoy two brand new sections.

New to Foller.me? Foller.me is a Twitter analytics application that gathers a bunch of interesting stuff from a public Twitter profile. Mike’s profile is a good place to start with ;)

My Twitter Account has finally been unsuspended

My Twitter Account has finally been unsuspended this morning. I wrote earlier that my account was suspended for no reason without any notification emails from Twitter support. The funny thing is even though it was unsuspended today, I got no response to the two tickets I filed so I don’t even know the reason why it was suspended in the first place. Oh well…

How To: Show Off Your Social Counters in WordPress

You know it’s all about social these days, and this post is about showing off how social you are on your WordPress website. I’m sure you’re using tonnes of social networks and all of them have friends, followers, fans and subscribers metrics, but let’s start from simple: Twitter, Facebook and RSS.

We’ll write code in this post, and you may ask me why. Of course there are loads of copy-paste javascript widgets available, but the first problem I encountered with those is they’re all different! What we’re going to do here is grab the numbers on the server, so then you’ll be able to display them however you like, with your own icons and captions.

I wrote a couple of posts on this topic last year:

We’ll be using some of those snippets in our code today, together with a few additions for Twitter followers count and RSS subscribers too. We will also adapt these to WordPress. Okay, enough talk, let’s get to the coding!


Icons Credit: Drink Web 2.0 by Bruno Maia

Twitter Followers Count

This one’s quite simple, since the Twitter API allows a non-authenticated call to public users. Assuming we’ve got JSON functions available (PHP5 or JSON Services in PHP4):

public function get_twitter_followers_count( $screen_name ) {
	if ( false === ( $followers = get_transient( 'twitter-followers-count' ) ) ) {
		$response = wp_remote_get( "http://api.twitter.com/1/users/show.json?screen_name={$screen_name}" );

		if ( is_wp_error( $response ) ) {
			$followers = 91;
		} else {
			$json = json_decode( wp_remote_retrieve_body( $response ) );
			$followers = $json->followers_count;
		}
		set_transient( 'twitter-followers-count', $followers, 60*60*24 );
	}
	return $followers;
}

As you can see I’m using the Transients API to cache the followers count for 24 hours, this reduced the load on the hosting server and serves pages faster. I’ll be using transients for Facebook fans and RSS subscribers too.

Line 5 might seem a little strange, we’re explicitly setting followers to 91. We do that when there’s an error with the API call so that we don’t show off a zero-count. You can go forward and extend it to double-cache values with a get_option and set_option call so that 91 is actually a figure retrieved from Twitter API and not hard-coded. But that’s extra, I’m fine with 91 ;)

The rest seems straightforward — we parse the response using json_decode and grab the followers count. If you’re into grabbing something else, go ahead and inspect the $json object using print_r, there’s so much interesting stuff there ;)

When the followers count is in our hands, we set a transient for it, so that next time it is served from cache, and finally return the count. Simple as that ;) The usage is easy — just pass a screen name to the function and you’ll get the results, as long as it is not a protected profile.

RSS Subscribers Count

As I already mentioned, transients will be used here as well, same method. Additionally we’ll be using Feedburner’s Awareness API. In order for that to work you’ll have to have your RSS feed setup with Feedburner and the Awareness API activated. Take a look at the “AwAPI Activation and the FeedCount Chicklet” section following the link above.

public function get_rss_subscribers_count($feed_url) {
	if (false === ($subscribers = get_transient('rss-subscribers-count'))) {
		$feed_url = urlencode($feed_url);
		$response = wp_remote_get("http://feedburner.google.com/api/awareness/1.0/GetFeedData?uri={$feed_url}&dates=" . date('Y-m-d', strtotime('-2 days', time())));

		if (is_wp_error($response)) {
			$subscribers = 97;
		} else {
			$body = wp_remote_retrieve_body($response);
			$xml = new SimpleXMLElement($body);

			$status = $xml->attributes();

			if ($status == 'ok') {
				$subscribers = $xml->feed->entry->attributes()->circulation;
			} else {
				$subscribers = 98;
			}
		}

		$subscribers = (int) $subscribers;
		set_transient('rss-subscribers-count', $subscribers, 60*60*24);
	}
	return $subscribers;
}

As you can see, we’re fetching the RSS feed data using the feed URL via an HTTP request to the Feedburner API. The Awareness API returns an XML object, which is then parsed using the Simple XML methods. The circulation attribute is the one we’re looking for — it indicates the approximate subscribers count.

Again, I’ve hard-coded the 98 figure there for fallback purposes, you might want to extend it. The date magic simply asks Feedburner for stats of two days ago, since it sometimes yields 0 for “today” and “yesterday”. Could be changed according to your Feedburner stats if that matters.

Finally, we’ve set the transient and returned the subscribers count, voila. Usage: pass on your Feedburner feed URL to get_rss_subscribers_count(), an integer is returned.

Facebook Fans Count

Last but definitely not least — Facebook. We’ll use the Facebook PHP SDK, I’m using version 2.1.2 which seems to be the latest stable at the time of writing. We’ll be using the Graph API way, so no more FQL queries please. Here’s the code:

public function get_facebook_fans_count($page_name) {
	if (false === ($fans = get_transient('facebook-fan-count'))) {
		require_once("facebook/facebook.php");
		$facebook = new Facebook(array(
			'appId' => 'your-application-id',
			'secret' => 'your-application-secret'
		));

		$graph_obj = $facebook->api("/{$page_name}");
		$fans = $graph_obj['fan_count'];

		set_transient('facebook-fan-count', $fans, 60*60*24);
	}
	return $fans;
}

Note, that unlike the old-fashioned way, the Graph API uses your application ID, not your API key. You can obtain these when registering a new application at the Facebook Developers page. There’s a button that says “Set Up New App” which takes you through the rest of the process.

So once your app is in place, credentials are fine and the connection is good, we use facebook’s api method to request for a page name. Try “mashable” for example.

The returned Graph object contains quite a lot of stuff, including the number of fans. Use print_r on $graph_obj to learn more. So the fan count is obtained, a transient is saved, and the number is returned.

Conclusion

Note that if you’re going to use these for different profiles, you’ll have to change the names of your transients to include that data, otherwise there will only be one cache. I kept the code as simple as possible here, but I’ve illustrated the extra stuff in the final source that I did. I also wrapped these up in a single class called $social, I know it’s too generic for WordPress, but I’m not writing a plugin out of this (yet). The source could be downloaded right here. Feel free to use and extend the code with your own methods for other social networks and services.

Okay well, thank you so much for reading and retweeting this, oh and by the way…

Question: what other 3-5 services would you like to get your numbers from?