how to successfully update all of your user’s profile offline, at once! – part 1

sounds crazy right? but actually you can make a great use of this feature in your facebook application. lets think that your application is kind of a todo-list or birthday reminder. now your users will create tasks or added friend to be notified when their birthdays arrive, or when the eta of a task is in 24 hours. in these cases you may have to update those user’s profile in background so that when they visit their profile page – they will see the latest information, and that will be very useful for them.

there are two ways to accomplish this task

1. by calling setFBML offline, using any of user’s session key.
2. by using <fb:ref /> with an url handler, which is a smart way indeed.

in this article i am going to focus on first technique. next article will focus on 2nd one.

updating using profile_setFBML()
to use this api offline, you first need a session key. the following code will print the session key for you.


<?php
echo $facebook->api_client->session_key;
?>

this code will output something like “6de106fa7e2de0820b091f12-503274632” which is my session key for this application.

now you can update all of your user’s profile using the following code. please note that i have used batch api for the sake of performance.


<?php
require_once 'client/facebook.php';

$appapikey = 'ff0b3d87fc42915533e15dc238f2d447';
$appsecret = 'app_secret_key';
$sessionkey = "6de106fa7e2de0820b091f12-503274632";
$facebook = new Facebook($appapikey, $appsecret);

$uid1 = 657561905;
$uid2 = 503274632;

$facebook->api_client->user = $uid2;
$facebook->api_client->session_key = $sessionkey;

$facebook->api_client->begin_batch();

$facebook->api_client->profile_setFBML(NULL, $uid1, "Offline profile <fb:name uid='{$uid1}' useyou='false' />", NULL, 'mobile_profile', 'profile_main');
$facebook->api_client->profile_setFBML(NULL, $uid2, "Offline profile <fb:name uid='{$uid2}' useyou='false' />", NULL, 'mobile_profile', 'profile_main');

$facebook->api_client->end_batch();
?>

if you need to update thousands of your user’s profile at a time, using the batch api is a must or you will suffer from timeout. now you can execute this script by either command line “php <script_file>.php” or by accessing it via browser :)

pretty neat, eh?

stay tuned for next part of this article where we will tell you how to update profile data offline using <fb:ref /> with an url handler :)

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google
  • blinkbits
  • BlinkList
  • Blogosphere News
  • description
  • E-mail this story to a friend!
  • Furl
  • Gwar
  • LinkedIn
  • Ma.gnolia
  • MySpace
  • Ping.fm
  • Reddit
  • Slashdot
  • Spurl
  • StumbleUpon
  • TwitThis
  • Upnews

9 Responses to “how to successfully update all of your user’s profile offline, at once! – part 1”

  1. Ehab  on February 3rd, 2009

    Very nice blog H Bhai ! Loading js in the footer – sooo good :D

  2. Omi Azad  on February 3rd, 2009

    Facebook is a pain in the ass :(

  3. TRIVUz  on February 3rd, 2009

    really very use full blog.. boss, keep it up.. let me back from trekking.. i’ll start exploring :-D

  4. Shahid  on February 3rd, 2009

    waiting for next………..

  5. Ishtiaque  on February 3rd, 2009

    To update all my friends profile, I always prefer setting it as a cron task. Recently I gave up using that technique since facebook announced that they will no longer be supporting the infinite session for users. But I guess now I can get back to the old stuffs. Thanks for the tips Hasin Bhai!

  6. lenin  on February 3rd, 2009

    Facebook’s new apps are making it look ugly. Users most often afraid to join/accept newer apps.

    But well… its a great opportunity for the developers…

    Keep writing for us :)

  7. Shoeb Abdullah  on February 3rd, 2009

    Awesome!

  8. ranacse05  on February 3rd, 2009

    Thanks . I was looking for this .

  9. xibic  on July 18th, 2009

    Really nice one..and helpful one…
    Please Post the Second one….quickly

Leave a Reply