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 ;)

Twitter Account Suspended

Account Suspended

Here’s a Thanksgiving surprise I got from Twitter today. Seriously, I’ve got a dozen accounts for brands and experiments I run using the Twitter API, but never on my own and funny thing, the rest are fine but mine’s suspended, and no single e-mail from them in my inbox! Contacting Twitter support, let’s see what they have to say.

Happy Thanksgiving!

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?

A Proposal to Solve the Bilingual Tweeting Problem

I was cleaning my Twitter account last week from unwanted peeps in the following list. It is really damn hard to keep up with a 1000 tweeps tweeting over 20 messages every second, only one of which could be valuable. So after I cleaned it up, I actually got a better stream from my friends, more tweets in Russian, and more personal tweets, rather than titles and links to blog posts via twitterfeed ;) which is why I tweeted this out:

@kovshenin: I just cleaned up my followings list. If you’re using twitterfeed and flooding my stream, I’ll unfollow you, unless you’re @washingtonpost ;)

Anyhow, this post is not about twitterfeed, spam or whatsoever, but it is about unwanted tweets in your timeline. Tweets in a language that you can’t read.

I myself sometimes tweet in Russian and are worried about my followers that don’t understand that, so I try to keep it at a minimum and mostly @ replies. This is good, but what if you really need to tweet in two different languages? Russian president Dmitry Medvedev has got two accounts, @MedvedevRussia and @MedvedevRussiaE and does the tweeting separately. I guess others do it the same way, but hey, what if you’re tweeting in 5 different languages? And what about 10?

Yes, Tweetdeck and other software can use Google Translate to translate the tweets, but that doesn’t work out quite well. What if I can speak two languages? I don’t need that fuzzy Russian to English translation, and believe me, neither do you!

I got a proposal to make this end. An easy one and a difficult one, and we’ll start with the easy one: attach a language code as an @ reply to the beginning of your tweet if it’s language specific, and to be able to read these sort of tweets you can follow that specific language code.

For instance, if I’d like to send out a tweet in Russian and wouldn’t like my non-Russian speaking followers to see it, I do this:

@ru My text in Russian goes here, whoever is not following the Russian language code will not see this.

And if I want to tweet one in German, I do the following:

@de My German message goes here, people not following that code won’t see it.

Here’s why it works. Twitter @ replies are public, but users don’t see them in their timelines unless they’re following both parties — the one issuing the message and the one mentioned in the message. I think this was one of the crucial changes to Twitter to reduce unwanted stuff in the public timeline, and almost resulted in a #followfriday fail.

So to see tweets tagged with the Russian language code all we have to do is simply follow @ru. I think that’s easy enough to understand, right? Anyways, one problem here that will need to be solved is the @ru @en @de and other Twitter accounts that are obviously registered ;)

Second option (the difficult one) is to get Twitter to introduce languages for tweets. I know they did this with Twitter Search and it seems to work okay, but this time there has to be something better — perhaps use Google to identify what language the tweet was issued in. And have profile settings where you can select the languages you’d like to see in your public stream.

This option would be ideal, but is difficult to implement, first option might be a little disruptive, but what I know for sure is that we have to get rid of multiple accounts created for separate languages. Hope you have a great day ;)

Tweet Button Showing Zero Count

I came across this issue a few days ago and started looking for solutions. Didn’t find too many decent ones, which is why I’m writing this post.

I’ve implemented Twitter’s Tweet Button on Foller.me last week and noticed that it always shows 0 count, despiting the fact that the page has been tweeted 3-4 times. My friends suggested to wait a while, but that didn’t help either. Count was still showing zero after 3 days, so I decided to inspect of what’s going on.

It turns out that Twitter has it’s own monster crawler called Twitterbot who sends HTTP HEAD requests to pages that have been tweeted. This flooded my error log with code 405 responses: Method not allowed. I thought that this is the part that was causing the 0 count and I was right. I solved it with only a couple of lines in my Python code, inside the WSGI handler (note that I’m running Google App Engine):

def head(self, screen_name):
    return

That was quite easy ;) Too bad the Twitter developers docs don’t mention this at all, and a Google search for Twitterbot shows you how to create your own Twitter robot ;) Thanks for sharing this, cheers!

Twitter Followers Count Snippet for WordPress

Here’s a short snippet to grab and display your twitter followers count in WordPress. You can use this anywhere, sidebar, posts, header, footer. We’ll be firing an anonymous call to the Twitter API for a user profile. This method does not require authentication, unless you’re trying to view a protected profile. To make this slightly easier I’ve used the JSON functions which are available in PHP 5, but you can easily get them to work in PHP 4 (and as Alex mentioned in the comments below, WordPress comes with it’s own JSON functions for PHP 4 users, which is awesome).

I’ve modified the snippet a little bit due to comments below, and thank you again Alex (@Viper007Bond) for clarifying things with the WordPress HTTP API and those very useful Transients. I actually grabbed some ideas from Alex’s own version of the Twitter Followers Count for WordPress snippet and added a fail-safe route (for times when the Twitter API is down).

Anyways, the snippet now consists of a single function, which checks for a transient (for caching purposes), then fires a query to the Twitter API, and in case of an error return a stored followers count value from the past. In case the Twitter API responded fine, we set a new transient and store the value as the last successful. Here’s the new snippet:

// Use this function to retrieve the followers count
function my_followers_count($screen_name = 'kovshenin')
{
	$key = 'my_followers_count_' . $screen_name;

	// Let's see if we have a cached version
	$followers_count = get_transient($key);
	if ($followers_count !== false)
		return $followers_count;
	else
	{
		// If there's no cached version we ask Twitter
		$response = wp_remote_get("http://api.twitter.com/1/users/show.json?screen_name={$screen_name}");
		if (is_wp_error($response))
		{
			// In case Twitter is down we return the last successful count
			return get_option($key);
		}
		else
		{
			// If everything's okay, parse the body and json_decode it
			$json = json_decode(wp_remote_retrieve_body($response));
			$count = $json->followers_count;

			// Store the result in a transient, expires after 1 day
			// Also store it as the last successful using update_option
			set_transient($key, $count, 60*60*24);
			update_option($key, $count);
			return $count;
		}
	}
}

echo "I have " . my_followers_count('kovshenin') . " followers";

Yup, quite simple isn’t it? Now call my_followers_count whenever you need to retrieve your followers count ;) Hope this will be of use to someone ;) Cheers!