How to (maybe) get WordPress Stats to accept the API key

WordPress stats is a nice little filter for WordPress, one of those devious hidden image IP trackers. Unfortunately, getting it to accept the API key doesn’t always work (even if it works for Akismet without complaint).

You may keep getting

Enter your WordPress.com API key to link this blog to your WordPress.com account. Be sure to use your own API key! Using any other key will lock you out of your stats.

even if the API key is correct. or if you hard code the API key

An API Key is present in the source code but it did not work.

The WordPress.com Stats Plugin is not working because it needs to be linked to a
WordPress.com account.

I didn’t find a solution in any of the forums, so I looked at the stupid script some more. Basically it uses the API key to get a “blog_id” (database index, most likely) from WordPress.com and can’t find one. So I made up a blog_id in the code. That shut up the plug-in, but of course stats aren’t tracked.

Finally, I went to http://dashboard.wordpress.com, logged into the account, made a new garbage *.Wordpress.com blog, then a bit later took out the made-up blog_id from the code, de-activated and re-activated, and … everything works. The external blog shows in the “Global dashboard.” Also the real blog_id is returned from code. But, if I take out the hard coded API key, it stops working again.

This is definitely a WordPress.com problem with registering externally hosted blogs, so to make it work, hard code the API key, make sure there is at least one *.Wordpress.com blog, wait a little bit, then re-activate the stats plug in.