Workaround to Facebook’s Graph API Search locale change

No Gravatar

So Facebook decided to change the meaning of the locale parameter to the search parts of the Graph API – and label the decision “by design” after 2 months of thinking. Not “design change” or “bug we don’t feel like fixing” – just “If it worked before – that was a mistake”. The handling of the problem is described in this bug-report.

If you do not use it, you probably don’t care, but if you do this would probably be fatal to your searches.

The problem

I would like to know what Facebook users in my country (Denmark) writes about my local branch of the phone company Telia. To find out, I would ask the graph:

https://graph.facebook.com/search?q=Telia&locale=da_DK

The locale-parameter would ensure that I only get results from danish Facebook sources. At least that was the case until December 5, 2012. After that, the locale-parameter changed role – now it will just localize certain field identifiers in the JSON reply. This is useless and all of a sudden I get heaps of irrelevant results from users in other countries in other languages. Facebook remains silent about what to do instead.

The workaround

For my projects I’ve used the following workaround – it’s Q&D, ugly and it takes up unnecessary resources, both for my own service and for Facebook, but it has been tested to work. One known drawback – if the same Facebook user mentions our search term more than once, only the last one is returned.

First – perform the search as always – in simple PHP (make sure to add your own validations):

<?php
$searchterm = 'telia';
$geturl = "http://graph.facebook.com/search?q=" . urlencode($searchterm) . "&type=post";
$fb_reply = file_get_contents($geturl, 0, null, null);
$fb_arr = json_decode($fb_reply, TRUE);
$reply_data = $fb_arr['data'];

Now $reply_data contains an array of posts – something like:

Array
(
 [0] => Array
 (
   [id] => 10002333417237_486897434763199
   [from] => Array
   (
     [name] => some name
     [id] => 100027398117237
   )
  [message] => Missing home
...

Look at the [from]-section to figure out who posted the message. Actually you are going to need all the from->id’s from all posts in the reply from Facebook. Why? Because you want to extract the senders locale and filter out any posts that does not match the locale you require. I use something like this to create an array of Facebook uid’s:

$users = array();
foreach ($reply_data as $pkey => $post) {
 $uid = $post['from']['id'];
 $users[$uid] = $pkey;
}

Next we ask Facebook about the users using FQL. Actually we only want to know about users if they have our locale:

$FQL = sprintf("SELECT uid, name, locale FROM user WHERE uid IN (%s) AND locale = 'da_DK';", implode(array_keys($users), ','));
$fql_query = "http://graph.facebook.com/fql?q=" . urlencode($FQL);
$fql_result = file_get_contents($fql_query, 0, null, null);
$fql_users = json_decode($fql_result, TRUE);

Now $users is a one-to-one mapping from users to matching posts, we’ll “join” the filtered user list with the $users-array and have – a list of posts from users with the requested locale:

$valid_posts = array();
foreach($fql_users['data'] as $dk_user) {
 $uid = $dk_user['uid'];
 $postkey = $users[$uid];
 $valid_posts[] = $reply_data[$postkey];
}

The $valid_posts-array now contains posts matching the needed locale – somewhat like before December 5th 2012.

Conclusion

I wonder why Facebook took the decision they did. It is just asking for workarounds like this. Now instead of one Facebook Graph request I will make two AND Facebook gets to send me a lot more data than I need. The data is still public (for now anyway) – let’s see if it stays that way.

IE7 content disappears

No Gravatar

This is not a complaint – it is the solution to an issue that has been puzzling me over the weekend.

IE8 has been out for a long time – which does not necessarily mean that corporations has implemented it yet. Some large corporations tend to make their business depend on current browser versions – not allowing them to upgrade the browsers on their pc’s without extensive testing and some time expensive application upgrades. I know of at least 5 danish companies who still doesn’t dare to take the plunge from IE6 (!)

I usually develop web-stuff having booted Ubuntu running Firefox – then once in a while boot Windows and test with the latest IE, Safari, Chrome and Firefox. I leave it to others to test on Mac’s. If I am unsure how something renders on other platforms, I can recommend browsershots.org – a cool service that renders a specific URL in any browser on any platform and allow you to see the screenshots after a while.

In this case the client is at IE7. The layout has a header, a content area and a footer – very simple stuff. It looks fine i all browsers – except for IE7. For this particular browser the content section wouldn’t display. Even IE7 displayed the area. The space was allocated but it was blank. This article on webmasterworld.com gave a few tips:

  1. add
    * { zoom: 1.0; }

    to the css (this did not make a difference for me)

  2. add
    position: relative;

    to the

    #wrapper

    in the css

Tip 2 made all the difference. #wrapper is a div that wraps around all the content on the page. Not knowing the inner workings of IE7, I can only guess why this fixed the issue – just hope Google finds this post for you if you run into the same problem.

Windows 7 – First learning points

No Gravatar

Installed Windows 7 RC2 for the first time yesterday.

In Virtual Machine

First installation in a VirtualBox – which worked fine except for the VirtualBox graphics adapter not being accelerated – which meant Solitaire ran extremely slow. Apart from that – no problems.

Dual/triple booting

Once the gut feeling was OK, i made room for Windows 7 on my laptop that already holds a Windows XP and an Ubuntu 9.04 partition. Installing Windows 7 leaves the existing OS’es alone, but the boot manager only supports Windows file-systems. My old GRUB bootloader would allow me to choose between booting Linux or Windows, but after the Windows 7 install, i could no longer boot Linux. The partition is still on the disk, but not in the MS bootloader. A bunch of hours later that was fixed – using the Ubuntu installer, GRUB was installed again – but I am still not quite satisfied; From GRUB i can boot into the MS bootloader. I now have two steps:

  1. Choose between booting Linux and Windows and (if choosing Windows)
  2. Choose between Windows XP and 7

I’ll try to fix this soon, but the priority of fixing this just dropped as I can now boot into all 3 OS’es.

One other thing: 3G USB modem

The last thing I needed was to the my 3 – 3G Huawei modem to work. In short: It didn’t – and it may not be because of Windows 7. Apparently the modem needs some Adobe Flash stuff and the drivers on the modems flashmemory are not Flash 10-compatible. 3 in Denmark knows and offers a download to fix the issue – It did the trick for me.

This post is my first written in Windows 7. Will post further findings..

Oh – and the wallpapers are beeeee-aaaaa-utiful!

Tip: Cool Firefox WYSIWYG blogging plug-in

No Gravatar

Actually there is no good reason for this tool not to be an independent piece of software – it doesn’t really need to be part of Firefox. But..

Somehow it just works for apparent reasons. Bloggers do two things a lot: Read blogs and write blogs and that is why ScribeFire is so cool – it’s right in the context where you want it. In Firefox:

  1. Go to the Tools-menu
  2. Choose Add-ons
  3. Choose Get Add-ons
  4. Type scribefire in the search box and search
  5. Install the add-on

Once installed, Scribefire is running all the time but display/hiding is switched with F8. It works especially well with WordPress blogs (such as this one) and configuration of one blog is done by entering the address of the blog + username and password.

If you feel inspired, click F8 and start typing. Something else came up, or the phone rang.. tap F8 and continue what you did before – and F8 it again to continue. So far it seems awfully nice.

Netbooks – the necessary new design test-tool

No Gravatar

Writing this on my Lenovo S10e netbook, I am furious. It’s before mid-day and yet I have had two experiences of software designs that did not consider netbooks a platform – or at least the new low screen resolution these computers imply. And before you call me a whiner (besides the fact that you’d be somewhat right), this is just a description of the changes I will make to include netbook users as an audience of software and website in the future.

Whine #1: Twice I’ve been cripled by software that saw the low screen resolution as a handicap – one of them on purpose. First I installed Pidgin – the cool cross-platform/cross-protocol IM and IRC client. I like it a lot, but on Windows some dialogs are too big and will not allow me to navigate to the OK/Cancel buttons at the bottomof the settings dialog. Fortunately this is Open Source stuff, so I can just participate and actively fix this myself.

Whine #2: I had to install a printer driver for my HP Photosmart 2575 printer – the install took over one hour because of some “ingenious” package system. That obviously poor user experience decision aside – the minimum requirement for the printer driver is a screen resolution of 800×600 pixels. My S10e runs at 1024 x 576. The consequence – I cannot print from my netbook in Windows because the printer driver won’t finish installing, as it has an irrelevant requirement. Fortunately I am dual-booting with Ubuntu, which has excellent support for my printer (without the requirement)

I’ve read somewhere that 20% of all computers that will be sold in 2009 will be netbooks. Some producers (including Asus) will stop production of 8.9″ -screen netbooks. The 10-inchers seems to dominate right now, and probably for the rest of the year (note: my guess only). Every company designing software will have to take this into account before they ship the next version of any product with a user interface.

I’ve worked on so many web projects with art directors saying: “Nobody runs 640×480 or 800×600 anymore”. Hey we know – but do you know how many users run with their browser maximized because a designer thought up a design that required it? Web designers don’t own the real estate of the users screen resolution – they can only hope to own the area the browser is sized to – and you have to count on users having at least one open history/bookmarks sidebar and/or plug-in and/or Google/MSN/Web developer toolbar enabled.

My point should be rather obvious: It is vital to include netbooks as testplatforms for serious UI-designers or your product will no longer be compatible with the equipment of the customers you want. The rules have changed – live with it.

You may argue that netbook users are asking for it, but if the competing website or software support the netbooks and you don’t – the users is no longer making the decision of leaving you.

Ubuntu two-finger scrolling

No Gravatar

My brother is now a fairly long time Mac-user. I haven’t gone down that road (yet). Last night he was here and i showed him my Asus EEE (which is currently running Ubuntu 8.10).

“Cool” – he said. “It supports two-finger-scrolling”. I didn’t know, but he is right. Googling for it found me this. Apparently the touchpad is new enough in the Asus EEE to support two finger scrolling. Nice to find hidden coolness.

Magpie RSS/Snoopy problem finally solved

No Gravatar

MagpieRSS IS great – I like it a lot, and it almost does exactly what you need to aggregate RSS feeds from PHP. MagpieRSS has one achilles heel in Snoopy. MagpieRSS relies on Snoopy as the HTTP-client (browser-component) that fetches feeds from websites – be it RSS or Atom formatted – It fetches files from a webserver.

The latests Snoopy release was in 2005 (as was the latest MagpieRSS), which could indicate that the development community has abandoned the code. The problem with Snoopy is that it has low tolerance to the use of carriage-return and linefeed characters in the header of HTTP responses from webservers. For some requests that means certain files, though rich in content, appear empty if they are fetched using Snoopy.

At first I tried downloading the latest Snoopy release from Sourceforge. It seemed to do the trick for some feeds, but aparently not all. Arnold Daniels came to my rescue. He has devised a wrapper – on the “outside” it appears to be Snoopy – but on the inside PHP’s Curl library has taken the place of a lot of the original Snoopy code. Give his alternative library a spin if you are using MagpieRSS for anything the should be somewhat resistant to deviations from standards.

Generate PDF files from PHP

No Gravatar

For a web project I needed to create invoices, to be downloaded or e-mailed to clients in PDF format. The platform is PHP and the documentation for this almost exclusively describe PDFLib for this purpose. I am sure PDFLib is fine, and the tutorials that come with the package looks really good.

But..

You pay for PDFLib – I don’t mind paying for software, you should pay for usable high-quality stuff, which I am sure PDFLib is. US$ 995 is a little steep though – compared to free. The FAQ however mentions a few free alternatives. Right now I am looking into FPDF – which seem to do the trick.

Actually I found out that my previous ISP (invoicing their customers only by PDF invoices via E-mail) use FPDF. This tells me that FPDF is more than ready for production. I’ll let you know if I something disappoints me – although I would hate to bash a truly free initiative such as this one. Oh – and by the way it has another edge to PDFLib – It is written in PFP and does not need server reconfiguration to work. If you want a head start, there are quite an extensive list of code examples available.

Light-weight XML editor

No Gravatar

XML Copy Editor LogoI was looking for an XML editor to perform a few simple tasks. Since i worked heavily with XML a few years ago, the Windows XML editor of choice is apparently still the Altova XML Spy. You can get it to do anything with XML (except – i think – transform XML to coffee). Negative minds would probably call it bloated and expensive. Positive minds would look for a cheap agile alternative.

Using the Open Source Alternative-site it is possible to find applications doing somewhat the same as commercial products. For the XML Spy query, the result is XML Copy Editor – a SourceForge application that has currently reached version 1.0.9. My needs were met as it:

  1. color-codes XML
  2. beautify/pretty-print XML with consistent indentations to increase readability
  3. opens files directly from URL’s

Also it XSLT transforms and has a small set of other features you may or may not need. Before you venture into extensive license bill-paying, you may try out this nifty little XML editor.