Facebook应用实例设置

I have an app that needs to have unique settings to each instance of a user adding it to their page (it is made to be added as a tab).

I have not been able to find any documentation to do this -- does anyone know how? Or does anyone have an example to follow or a place to learn?


SOLUTION

I made a section on the Tab for the app user's page that only shows to admin's of Page. It links to a page in my app sending the page_id to my page. This allows me to now store information (and settings) in my database based off the page_id.

I found that Facebook has a section to go to an App's settings page (which you can set up in your application settings via the Developer App) which also sends the page_id -- but it doesn't send it in an encrypted sense, so I encrypted the page_id with my settings option.

If anyone needs further explanation, feel free to message me I would be happy to help.

I'm pretty sure what you are looking for is the "page" instance. Every page has a Facebook ID just like every user does. For the most part, you can use a page ID anywhere you would a user ID. What you want to do is capture the ID of the page, not the ID of the user adding it to the page (the admin). Scroll almost all the way to the bottom if this URL to see how to grab the page ID: http://developers.facebook.com/docs/guides/canvas/

Basically, an additional parameter is included call "page" that will contain the page ID. Use that to interact with the page and store any session information.

You can use database to store the settings of each instance of a user, with a unique key (use php's uniqid function).

App can retrieve the settings based on key with respect to the user.

When a user goes to your app by accessing a tab in another page your app receives a POST var called signed_request.

In PHP, this var can me decoded by the following way:

function parse_signed_request($signed_request, $secret) {
  list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

  // decode the data
  $sig = base64_url_decode($encoded_sig);
  $data = json_decode(base64_url_decode($payload), true);

  if (strtoupper($data['algorithm']) !== 'HMAC-SHA256') {
    error_log('Unknown algorithm. Expected HMAC-SHA256');
    return null;
  }

  // check sig
  $expected_sig = hash_hmac('sha256', $payload, $secret, $raw = true);
  if ($sig !== $expected_sig) {
    error_log('Bad Signed JSON signature!');
    return null;
  }

  return $data;
}

function base64_url_decode($input) {
  return base64_decode(strtr($input, '-_', '+/'));
}

$arr = parse_signed_request($_POST["signed_request"], "YOUR_APP_SECRET");

echo print_r($arr);

Probably you can use the $arr["page"]["id"] to know which page accessed your app.

You can read more about that here:

http://developers.facebook.com/blog/post/462/

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

Hope it helps!