Tuesday, February 8, 2011

Can't seem to POST picture= links using the Facebook API?

Some links are already URL-encoded, so you have to watch-out when posting to the Facebook Graph API, especially when trying to post on someone's wall not to accidentally try to invoke urllib.urlencode().

One way is to use the unquote() function in the urllib() to first decode it:
if picture:
        picture = urllib.unquote(picture)

Then when you use urlencode data again, you can have some piece of mind that the code will be posted correctly. One way is to grab the ID returned by the POST call, and then JSON-decoding the response to verify that the dictionary has the 'picture' keyword:

response = urllib.urlopen("http://graph.facebook.com/%s" % id).read()
json_data = json.loads(response)

self.assertTrue(json_data.has_key('picture'))

The issue is similar (not sure if it's related) to the bug reported at: http://bugs.developers.facebook.net/show_bug.cgi?id=11970

No comments:

Post a Comment