Facebook iFrame app - how to get Preload FQL result using PHP SDK?

for several years I have an FBML application (a small Flash game ) that I am trying to convert to an iFrame application now. Unfortunately, there are still few documents for iFrame Facebook applications.

For my game I need a username, image, gender and city.

In my old version, I had this preliminary FQL (created once by a PHP script):

$fql = array('info' => array('pattern' => 'facebook', 'query' => 'SELECT first_name, sex, pic_big, current_location FROM user WHERE uid={*user*}')); $fb->api_client->admin_setAppProperties( array('preload_fql' => json_encode($fql))); 

and then my FBML script application was as simple as:

 <?php require_once('facebook.php'); define('FB_API_ID', 'XXX'); define('FB_AUTH_SECRET', 'YYY'); $fb = new Facebook(FB_API_ID, FB_AUTH_SECRET); $viewer_id = $fb->require_login(); $data = json_decode($fb->fb_params['info'], true); $first_name = $data[0][0]; $last_name = $data[0][2]; $female = ($data[0][3] != 'male'); $avatar = $data[0][3]; $city = $data[0][4]['city']; # and then I'd just construct flashvars attribute # for the <fb:swf ...> tag and print it ?> 

Does anyone have any tips on how to recreate the same script for the iFrame version, i.e. how can I get Preload FQL result using iFrame application ?

According to an old Facebook blog post, Preload FQL should be available for iFrame applications .

Thanks! Alex

+4
source share
3 answers

My own answer after a long search is that Preload FQL results are not sent to Facebook iframe applications.

This is why the performance report :

"Preliminary FQL query and multicomponent query.

This section applies to FBML canvas pages, but not to web pages or IFrame canvas pages.

+3
source

Like Facebook said for Preload FQL

"Facebook will send the result of these FQL queries as JSON encoded POST parameters to your Canvas URL."

print_r is your $ _ POST and see which variable is "json-encoded results". You convert json to php object using json_decode

JSON looks like this: {"var":"val","var":"val"}

In addition, Facebook already has excellent docs for iframes. Then you may have missed these great documents:

Facebook Docs Home

http://developers.facebook.com/docs/

Authentication

http://developers.facebook.com/docs/authentication/

Signed Request

http://developers.facebook.com/docs/authentication/signed_request/

Apps for iFrame Canvas

http://developers.facebook.com/docs/guides/canvas/

PHP SDK

https://github.com/facebook/php-sdk

Graphics API

http://developers.facebook.com/docs/reference/api/

0
source

You do not need to invoke FQL for the information you receive. For iFrame, you just need to follow these steps.

  • Download the PHP SDK graphics api https://github.com/facebook/php-sdk/

  • Create an object and authorize the application from the user

      $fbconfig['appid' ] = "your application id"; $fbconfig['api' ] = "your application api key"; $fbconfig['secret'] = "your application secret key"; try{ include_once "facebook.php"; } catch(Exception $o){ echo '<pre>'; print_r($o); echo '</pre>'; } // Create our Application instance. $facebook = new Facebook(array( 'appId' => $fbconfig['appid'], 'secret' => $fbconfig['secret'], 'cookie' => true, )); // User location extended permission allow you to get user current location $loginparams = array('canvas' => 1,'fbconnect' => 0,'req_perms' => 'user_location'); $loginUrl = $facebook->getLoginUrl($loginparams); // We may or may not have this data based on a $_GET or $_COOKIE based session. // If we get a session here, it means we found a correctly signed session using // the Application Secret only Facebook and the Application know. We dont know // if it is still valid until we make an API call using the session. A session // can become invalid if it has already expired (should not be getting the // session back in this case) or if the user logged out of Facebook. $session = $facebook->getSession(); $fbme = null; // Session based graph API call. if ($session) { try { $uid = $facebook->getUser(); $fbme = $facebook->api('/me'); } catch (FacebookApiException $e) { d($e); } } function d($d){ echo '<pre>'; print_r($d); echo '</pre>'; } 

    // You can find all the data in this array. print_r ($ FBME);

For more details see this lesson http://thinkdiff.net/facebook/php-sdk-graph-api-base-facebook-connect-tutorial/

Hope this works for you.

0
source

All Articles