Plurk AS3 Bridge

Update: February 23rd, 2010

Since Plurk released it’s API last December, it’s no brainer that I, as Plurk user and Flash programmer, to try to implement Plurk functionality into Flash app.
I encounter problem with crossdomain issue (really common in this line of work :D ), but thanks to Plurk developer responsiveness, they already add crossdomain.xml in their site root (http://www.plurk.com/crossdomain.xml).

When developing Plurk app using AS3, I also use a very helpful class to manage API call between Flash and Plurk.
Inspired from ZeroFractal’s FacebookBridge simplicity and ease of use, I write PlurkBridge as a simple Actionscript 3 bridge class to enable easy communication between Flash app and Plurk API.
This class doesn’t wrap every Plurk API method, but instead written so it be able to call any method available.

All in all, PlurkBridge is:

  1. Simple
    Plurk API call and handling can be done as few as two step. PlurkBridge initialization and load call (see example below).
  2. Consistent
    This PlurkBridge class remain flexible and independent from any change or update on the API by Plurk Developer.
    You don’t need to learn new method/parameter here, just use Plurk API official documentation page directly.
  3. Lightweight
    PlurkBridge class itself only have 7kb in size.

Example code:

import com.harsanalif.plurkbridge.PlurkBridge;

var API_KEY:String = "myPlurkAPIKey";
var USERNAME:String = "myUsername";
var PASSWORD:String = "myPassword";
var METHOD:String = "/API/Users/login";

var bridge:PlurkBridge = new PlurkBridge();
bridge.load(METHOD, { api_key:API_KEY, username:USERNAME, password:PASSWORD }, onComplete);

function onComplete(result:Object):void
{
   if(result.error_text)
   {
      //Error handler
      trace(result.error_text);
   }
   else
   {
      //Success
      trace(result.user_info.display_name);
   }
}

You can see the Flash demo in action using PlurkBridge class here:
PlurkBridge Demo

You can download the source and example here:
PlurkBridge

Known issue:

  • Plurk native error (invalid_login, invalid_plurk_id, etc) can only be handled correctly with Flash Player 10 because of limitation in HTTP Header handling in previous Flash Player version.
    I suggest you target Flash Player 10 when using this class.
  • Also, as pointed by Focus1921 in his blog post, this class can’t handle image related API method, specifically, API method that need to use multi-part POST request.
    I have tried various method on this but no success. For now, if you really need upload image functionality for Plurk API, you can use revised version of Plurk AS3 Bridge class by  Focus1921 (LINK). Special thanks to Focus1921 for this workaround :)
    If you can find other workaround/hack to be able to use /API/Users/updatePicture & /API/Timeline/uploadPicture in AS3, please let me know.
  1. Marianne
    January 19th, 2010 at 22:44
    Reply | Quote | #1

    uhmm., can you each me how to use the Plurk API.? :( (

    • Alif Harsan Pradipto
      January 20th, 2010 at 08:55
      Quote | #2

      Hi Marianne.
      Plurk API using simple HTTP request that returning JSON encoded data.
      Check HTPP request method on your programming language of choice, or if you using Flash CS3/CS4, just download PlurkBridge class directly and type example code above on Action panel. Of course you need to insert your own API_KEY, USERNAME, and PASSWORD.
      Check http://www.plurk.com/API for more info and implementation on other programming language.

  2. January 20th, 2010 at 02:48
    Reply | Quote | #3

    Mantep, sampai dipublikasikan plurkapi :D
    Btw ini saya juga coba iseng buat saja
    http://files.yohang.web.id/plurkflash.html :D

    • Alif Harsan Pradipto
      January 20th, 2010 at 08:59
      Quote | #4

      Thanks :D
      Aplikasimu keren, simple but solid! Cocok buat widget Plurk pribadi :D

    • March 9th, 2010 at 18:23
      Quote | #5

      mau nanya mas..
      kalo udah jadi aplikasinya trus diupload kmn ya ?
      itu dalam bentuk formatnya apa? flash swf?

  3. January 20th, 2010 at 14:13
    Reply | Quote | #6

    this blog is nice for solving my problems~

  4. February 9th, 2010 at 10:49
    Reply | Quote | #7

    how will i get the API badge?

    • Alif Harsan Pradipto
      February 9th, 2010 at 11:29
      Quote | #8

      Hi Anthony,
      To get API Badge on Plurk, you need to develop a public app using Plurk API, and tell Plurk team the application description and it’s link (via their Contact Form).
      If you’re lucky, you’ll get the plurk badge in a moment.

  5. February 19th, 2010 at 10:42
    Reply | Quote | #9

    .. can you teach me how to use this ? please ..

    • Alif Harsan Pradipto
      February 20th, 2010 at 10:49

      Hi Roxie,
      Just download the example file above, open it with Adobe Flash CS3, enter your Plurk API key (that you can get from plurk.com/API), and you’re ready to go :)
      If you already familiar with how working with Actionscript 3, I think it’s not that hard to understand example code above and try to write your own code.
      If you have more problem, let me know.

  6. Alif Harsan Pradipto
    March 9th, 2010 at 19:04

    kriz :

    mau nanya mas..
    kalo udah jadi aplikasinya trus diupload kmn ya ?
    itu dalam bentuk formatnya apa? flash swf?

    Hi Kriz,
    Kalo udah jadi bisa diupload kemana saja, seperti tempat hosting file swf kayak http://megaswf.com/ ato http://www.swfupload.com/. Tapi lebih baik kamu upload ke hostingan kamu sendiri sih kalo ada.
    Yup, formatnya tetap .swf

  7. April 4th, 2010 at 17:45

    Wow keren Mas..
    Saya cobain di AIR ya.. :D

  8. May 10th, 2010 at 16:05

    keren banget ya

  9. グリンプ
    July 9th, 2010 at 22:57

    Excuse me , can you tell me how to display characters which is not english characters? They show as a block!

    • Alif Harsan Pradipto
      July 15th, 2010 at 19:58

      You’ll need to embed the non-english character on the TextField in Flash.
      Sorry about this, but I’m haven’t embed non-english character for the textfield in my example app (thus showing blocky character if you used non-latin font).

  10. August 25th, 2010 at 12:51

    keren2

  11. 1 trackbacks
TOP