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.
Related
currently all bots developed by me (including several production bots which have been in use for a while) stopped replying to messages. According to logs, Messenger is returning the following response:
(
[error] => Array
(
[message] => An active access token must be used to query information about the current user.
[type] => OAuthException
[code] => 2500
[fbtrace_id] => C9ExJBwjvfp
)
)
This is deeply frusturating, because the bots have been working well and the issue appeared in deployed bots which have been working independently for a while.
The request is as follows:
(
[recipient] => Array
(
[id] => 1783672501695199
)
[message] => Array
(
[text] => MESSAGE_TEXT
)
[tag] =>
[notification_type] => REGULAR
[messaging_type] => RESPONSE
[access_token] => XXXXXXXX
)
Is there a known bug or a backwards incompatible change in API? Had anyone encountered this issue?
This usually happens when the user who authorised a Facebook Page for given Facebook App revokes the token. This is generally possible from Facebook settings page (see Apps or Business Integrations).
You can fix it by re-authorisation of your Page in developer's portal (select your Facebook App, navigate to Settings and scroll to "Token Generation" section). If you don't have the Facebook App than you have to do it in the app of your bot provider.
Notice that there is an ongoing procedure of all Facebook App required to be approved again. But the final deadline is the 1st of August. So this should not be the case.
For me the problem was the PHP library I was using that sent the data to FB API by encoding with query string. As soon as I changed that with json_encode the problem was fixed. Hope that helps anyone.
It was actually a bug and it was fixed
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).
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"}"
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.
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.