Facebook app_data - facebook

Can someone explain to me how to use facebook app_data which is part of the signed request?
http://developers.facebook.com/docs/authentication/signed_request/
The documentation is vague. I can't figure out how to actually use the app_data field. I want to be able to pass the app data to the app when it is added to a page so that the content displayed on it is relevant to the Facebook page.
for example I want a user profile on my site to only be displayed on that users facebook page. To do so I want to send the user ID to the fb signed request when the user adds the app to their page. Then anytime the page is visited I will pull the app data and run some php to display the correct profile.
Can I do this with the app_data or is this not possible?

From the documentation that you have cited
App Data is
A JSON string containing the content of a query string parameter also called app_data. Usually specified when the application built the link to pass some data to itself. Only available if your app is an iframe loaded in a Page tab.
So app data is useful only when your application has generated a link that some user will click and follow through to your app on some Facebook page.
And if a user is visiting some page (and the app tab) directly, then you won't get the app_data field.
Once a user has installed your app (and has given your app minimum permissions) on any one of their pages, you always have the page_id and user_id fields in the signed_request that Facebook will send to your app, both in canvas apps (no page_id field) and page tab apps.
For what you want to do, you can just read the signed_request and then find out the page_id and display data accordingly, you do not even have to use user_id.
Hope this answers your question. Do ask for clarifications, if required.

Related

get the facebook user id in fan page using js

I use "html static iframe tab by woobox" to create a fan gate.
The fan gate shows differnt pages for users who liked the page, and another page for non-likers.
I have two aspx pages on my server one for likers and one for none-likers.
For the likers page whitch has an Iframe I link my first webpage.
In this webpage i want to get the facebook userid that is currently in the likers page.
Do I have to create an application in order to get the userid?
Do i have to get the user permission?
How do i use js sdk to do it?
Thanks
Yes, you have to create an App to get the User ID, and the user must authorize your App. See here for further information about login with the JavaScript SDK: https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.0
But keep in mind that you will NOT get the real User ID, Facebook made some changes recently and you can only get an "App Scoped ID" - see the Changelog for further information: https://developers.facebook.com/docs/apps/changelog
DonĀ“t worry, the App Scoped ID will not change, even if the User deauthorizes and authorizes your App again.

perl Facebook::Graph API check if user likes page

I'm using Facebook::Graph and any time a page is loaded, I would like to detect server-side if a user has liked a certain page or not. I can't find in the documentation how to do this though. Is it possible to do this without sending the user ID to my server-side script? Because I know using the javascript SDK you can check this, but I feel like it might be different with a server-side API.
Not sure what you mean with "anytime a page is loaded"... I guess you mean an page of an App? If so, you need the user_likes permission to be able to get the information on the User's likes.
If you're using a Page Tab App, then you could get this info out of the signed_request which is passed to the App once the User accesses it from the Facebook Page Tab. See https://developers.facebook.com/docs/reference/login/signed-request/ The indicator is in the page.liked field.

Fan and nonFan pages for my app

I want my application to have two spare screens, one for the non Fan user (the ones that didn't press the button like) and one for the fans. How can I do that without asking the users to authorize my app? Do I have to use pages or page tabs first? or something else?
I tried with JS SDK and $_REQUEST["signed_request"] but there is no info if the user "likes" the app. I also tried FQL methods, but the most tables ask for the user_likes permission.
I'm totally lost with that and any help would be gratefull.
You can get this from the signed_request parameter, which is added to the request URL for your app on the page tab or canvas URL you provided. The signed_request param contains JSON data which includes the id of the page your app is installed on, and an additional liked field if the user has already liked the page. You can use this field to redirect users to the appropriate view for your app.
See the section labelled "Integrating with Facebook APIs" at https://developers.facebook.com/docs/appsonfacebook/pagetabs/ for more info.

Send user to friend's profile within canvas app via automated URL in emails?

Question from a product management perspective at a company which will offer a complete UI of our product within our Facebook canvas app.
The desired functionality of a feature would be:
Registered user receives email suggesting friends to recommend our service to.
Email contains generated URL to our Facebook canvas app.
When clicked and opened, canvas app lands on page with information about suggested friend.
Is it possible to automate a URL that would trigger this?
You can pass information in to you canvas app using the app_data parameter in the URL. The passed app_data is then made available as part of signed_request. You can find more at http://developers.facebook.com/docs/authentication/signed_request/
As an example, you could use the following URL
http://apps.facebook.com/mycanvasapp?app_data=some_app_data
The app_data variable of signed_request would then contain the string
some_app_data
If you need to pass something complex though app_data, I believe the most common method is to pass it as a JSON formatted string (see http://www.json.org/ for more on JSON).

Facebook friend validation on an external website

I'm interested in using Facebook as a way to validate that someone is my friend on an external site, and based on that, show them special content.
Inside Facebook, consider this scenario:
I post photos and give permission to friends only
Someone tries to view my photos by URL
If that person is my friend, Facebook displays the photos.
I want to mimic this behavior on my own personal website:
User follows a link to "private" content
My site (either by server-side, JS, Ajax, iframe, whatever) asks Facebook if the person is logged into Facebook in their browser.
If not, user is presented with a Facebook popup to log in.
When the user is logged in, my site asks Facebook if they are my friend (ID coded into the site), and if so, presents them with the content
Is this possible without requiring the user to "authorize" my site or application? My only idea (based on http://wiki.developers.facebook.com/index.php/Authorizing_Applications) is that I could create an application for my site, and then on the external site, load my Facebook application in a hidden iframe (which would in turn load my site in an iframe) to give my site the Facebook user ID and store it in the session.
What is the best way to accomplish this?
Yes, this should be possible. You would have to utilize Facebook Connect. The basic flow would be something like you described above:
User on your site follows a link to
private content. This content is
marked in your database (or otherwise) with the owner's Facebook Id.
Your site uses the Facebook API to
check whether the visitor is logged
in to Facebook. If not, deny
access.
If they are logged in, you can
utilize the friends.areFriends API method
to compare the visitor's Facebook ID
with the content owner's Facebook
ID. If they aren't friends, deny
access, otherwise you can show it.
Facebook Connect is actually fairly easy to implement, despite the terrible docs that are hard to understand. Once you have it up and running, it basically means that any visitor to your site that is logged in to Facebook will provide you with a session key that you can use to query Facebook for information about them.