Facebook application timeline tabs - facebook

I have a question about the timeline tabs. I have created an application which has been installed on 2 different business pages as tabs. Now what I want to do is change the content of the tab based on which business page is being viewed. Another company has done this but I can't work out how. Any thoughts?

This is pretty easy to do. If you decode the signed_request data POSTed to your page, you can see what page is 'looking' at your app (i.e. which page the app has been installed on).
If you decode the data (e.g. in PHP you can do: print_r( $facebook->getSignedRequest() ); to print the decoded version), you will see something like:
Array
(
...
[page] => Array
(
[id] => 1234567890
[liked] => 1
[admin] => 1
)
[user] => Array
(
...
)
)
The $response['page']['id'] is the ID of the Page that is looking at your app at that moment. You can store the IDs of the page that have installed your app, and check it with this to determine which content to load up.
You will also notice that the data includes $response['page']['admin'], which tells you if the user looking at the page is an admin of the page (1=admin, 0=not admin). And $response['page']['liked'], which tells you if the user looking at the page is a fan (1=fan, 0=not a fan).

Related

One FB application to more than one FB Page

I want to add a an FB application to more than one FB Page.After the user's authentication , rediraction to my application's url I can't find a way for the application to know the page which the request was made. Thank you in advance for your help
You will get the page id in the signed request.
FYI: Signed Request
This is pretty easy to do. If you decode the signed_request data POSTed to your page, you can see what page is 'looking' at your app (i.e. which page the app has been installed on).
If you decode the data (e.g. in PHP you can do: print_r( $facebook->getSignedRequest() ); to print the decoded version), you will see something like:
Array
(
...
[page] => Array
(
[id] => 1234567890
[liked] => 1
[admin] => 1
)
[user] => Array
(
...
)
)
The $response['page']['id'] is the ID of the Page that is looking at your app at that moment. You can store the IDs of the page that have installed your app, and check it with this to determine which content to load up.

iframe loaded in Facebook page tab: signed_request returning 'profile_id' not 'page'

This is driving me crazy. I know a lot of people are having problems with empty signed_request parameters ... this not one of those questions!
I get the $_REQUEST['signed_request'] data and decode it in PHP without problem. I am using an iframe canvas to create a page tab, one of those 'click like to access more info' pages that are very popular at the moment.
The problem is the signed_request data does not contain a ['page'] field as expect, it contains a ['profile_id'] which is meant to be for "apps written in FBML and loaded in a Page tab" (from https://developers.facebook.com/docs/authentication/signed_request/).
I have checked and checked my settings, it's definitely an iframe canvas. Is anyone else having this problem?!
Example of decoded signed_request data:
Array ( [algorithm] => HMAC-SHA256 [issued_at] => 1320926195 [profile_id] => XXXXXXXXXX [user] => Array ( [country] => au [locale] => en_US [age] => Array ( [min] => 21 ) ) )
I managed to fix this problem by recreating the app. The old app was created a while ago when FBML was still an option, even though I'd changed the settings to iframe it was causing some legacy problem.
Anyway, nuking the app settings and starting again fixed the problem!
I had the same problem but creating another application wasn't an option to me. I started trying different configurations and I managed to start receiving the expected response when I activated the migration option Page Tab iframe
In your application Settings -> Advanced -> Page Tab iframe -> Enabled
You will then receive something like:
{"algorithm":"HMAC-SHA256","expires":0,"issued_at":1334321200,"oauth_token":"AAAAAZAj4rx20B4E3Z5BWYJwyfZATJFE9j0P3AXZAnEum451qFiIXnhCvzmZCFIZCmZCc83JKUsiyhzRSpFDXHEXzmeBIqjHdVxtWI1xNBSCPzwZDZD","page":{"id":"259117083013","liked":true,"admin":true},"user":{"country":"es","locale":"en_US","age":{"min":21}},"user_id":"342"}"

Facebook Graph api How to get page ID via an access token

For "users" on Facebook, I gather information like their user ID by using this graph api call:
https://graph.facebook.com/me?access_token=...
This works every time.
My question is... is there a way to get the page information about the page that was just authorized via the access token that is returned after authorization?
I tried this, and id doesn't work, but this is what I'm looking for
https://graph.facebook.com/page?access_token=...
As you know, in order to post to a "page" wall is to 'Post' like so...
https://graph.facebook.com/PAGEID/feed?message=blahblah&access_token=XXXXXXXXXXXXX
How do I get the page ID and other info about the page that was authorized without already knowing the ID or page "username" (which you have to have 25 likes to use anyway)???
Thank you for any help stackoverflow community:)
The answer I was looking for is here. You can simply use a users access_token to get a set of their page_access_tokens, and give them the option of posting to these pages using these access tokens based on the return JSON object data.
pages are not authorized, applications are.
in case that your application has permissions, the current page is informed thru the signed_request that FB passes to the app canvas. use the php sdk to read it
https://developers.facebook.com/docs/authentication/signed_request/
There's no callback when an application is installed on a page. However, if a user is using your application via a tab iFrame you can get that pages id from the signed_request. You could maintain this information as part of your own user session, and use it as you see fit.
The contents of a signed_request to a tab iFrame would be similar to the following (output of PHP print_r):
stdClass Object
(
[algorithm] => HMAC-SHA256
[issued_at] => xxxxxxxxxx
[page] => stdClass Object
(
[id] => FAN_PAGE_ID // target page id
[liked] => 1 // is the user a fan
[admin] => // is the user an admin
)
[user] => stdClass Object
(
[country] => ie
[locale] => en_GB
[age] => stdClass Object
(
[min] => 21
)
)
)
For more information see:
http://developers.facebook.com/docs/authentication/signed_request/
You may also want to take a look at the manage_pages permission
Also, see here:
http://developers.facebook.com/docs/reference/api/
Page Login
You can impersonate pages administrated by your users by requesting the manage_pages permission.
Once a user has granted your application the "manage_pages" permission, the "accounts" connection will yield an access_token property for every page administrated by the current user. These access_tokens can be used to make calls on behalf of a page. The permissions granted by a user to your application will now also be applicable to their pages.

Facebook API - how to get page ID using Facebook API?

With Facebook API, within a custom app added to a fanpage (tab app), how do I get the fanpage ID?
Here's what I'm trying to achieve:
user goes to the full-width canvas app, he authorizes himself there and allows the app to add a tab to one of the fanpages he's administrating
every Facebook user going to that fanpage, sees the tab and the tab shows content specific to that fanpage (that's why I need to know the fanpage ID)
if fanpage administrator wants to change something, he goes to the full-width canvas and logs in to my service (here's where I store what he wants to show in his Fanpage)
From a parsed signed request (to an tab iFrame) you can get the page id - the contents would be similar to the following (output of PHP print_r):
stdClass Object
(
[algorithm] => HMAC-SHA256
[issued_at] => xxxxxxxxxx
[page] => stdClass Object
(
[id] => FAN_PAGE_ID // target page id
[liked] => 1 // is the user a fan
[admin] => // is the user an admin
)
[user] => stdClass Object
(
[country] => ie
[locale] => en_GB
[age] => stdClass Object
(
[min] => 21
)
)
)
For more information see:
http://developers.facebook.com/docs/authentication/signed_request/

facebook: how to show content in page only if user likes it

how can i show or display information only if the user is fan or likes my page? there are several pages that do that to catch more fans. thanks!
edit:
like the victorias secret page with this box
http://www.facebook.com/victoriassecret?v=app_117241824971601&ref=ts
My answer applies if you use an iFrame for your tab/canvas. First, you need to ask for permissions (just need basic info from user). Then, make a call to the Javascript API, like so:
FB.api('me/likes', function(response) {
});
This gives a JSON object of everything the user has liked. So, you have to loop through the response and try to find your page. If you are successful in finding it, display the awesome content!
Hope this helps!
Edit: Looking back, my answer was way off. This information is actually contained in the signed_request given by Facebook.
If you mean Facebook Page, use functions from Facebook API: Signed Request
$signed = parse_signed_request($_REQUEST['signed_request'], YOUR_APP_SECRET_KEY);
$signed = Array (
[algorithm] => HMAC-SHA256
[expires] => 13..
[issued_at] => 13..
[oauth_token] => ...
[page] => Array (
[id] => 29...
[liked] => 1
[admin] =>
)
[user] => Array ( [country] => cz [locale] => en_US [age] => Array ( [min] => 21 ) )
[user_id] => ..
)
If current user like your Facebook tab page, you find out from $signed['page']['liked']
If you're using the php sdk, you can use a call to the facebook object api and then determine if they have the like you want them to have.
$path = 'me/likes';
$likes = $facebook->api($path);
More info here
This is a privacy and security setting. Facebook Privacy FAQ
Page Tabs gets Signed Request that contain "liked" field
http://developers.facebook.com/docs/authentication/signed_request/
FQL isFan
http://developers.facebook.com/docs/reference/fql/page_fan/
Old REST API isFan
http://developers.facebook.com/docs/reference/rest/pages.isFan/
Legacy FBML isFan
http://developers.facebook.com/docs/reference/fbml/visible-to-connection/
There doesn't have to be any code involved. Just create a landing page (you could create a jpeg photo and link to the photo) and set that as the default landing page in your page settings. For users who are fans they go directly to the wall posts. All other people (non-fans) go to your specified landing page.
By the way, you realize that people can still access your content by just clicking on one of the tabs, correct? Even the Victoria Secrets example allows you to click on the "wall" tab, for example, and see the content.
A lot of people just like the page because it's the default landing page and they "think" they have to like the page first. It's more social psychology than anything else.
Google for Facewall Script, that should do what you want. But keep in mind to offer an option for users that not have Facebook Account.