Tracking user activities on facebook - facebook

I've created a Facebook page and implemented an application for it too. Now, my aim is that, a user must like and share page with at least one friend to be able to participate/to get access to the app and consequently use it (play the game). Or simply force a user to like and share the page. Can you please tell me if this is even possible and how it can be achieved?

When user visits your Facebook page, you receive signed_request , which contains some information about the user, including whether or not the user liked your page. For share, you will probably need to implement send dialog. In documentation it is said that user takes action (send or cancel) he will be redirected to url you set up, and if the action was "cancel", there will be an error.
So you will probably need to create db where you store user id and whether or not he shared your page before (since you can check if he liked the page at any time).

Related

How to get user likes in Facebook before asking permissions

I have a client who wants to have the user liked his app before asking for permissions.
For users not having defined advanced security settings in their profiles this is possible, but I have occasions that I must ask for user_likes permissions to get that info so this is a dead end.
One solution could be to have my own like button in the page and register FB.event.subsribe to collect the info, but because the app will be used in a page tab (where a like button is already displayed by FB on top) this would be ugly and confusing.
Any ideas?
Within a page tab app, you get the info whether the viewing user liked the page already or not in the signed_request. (Since it is POSTed to your app on initial load into the iframe, you can only access it server-side.)
For how to parse it, see here: https://developers.facebook.com/docs/facebook-login/using-login-with-games#parsingsr
(If you are using the PHP SDK, that has a method to get it parsed implemented already.)

Facebook get user id

I am making a simple contest on Facebook which is a form to fill in.
I would like to add a mechanism with share options.
You will win another chance for each friend who will click on the back link.
Technically i wish to add to the shared url the user id to add 1 chance for him in my database (sharing options will appear after the form)
So i need the user id but i don't want to display the FB popup "accept this application" before launching my app. Is it possible?
If not, do you have an id or online to do it with open graph and all that stuff?
There is no way to get the User-/Facebook-ID of the user without login/authorization. The signed request variable only presents basic infos if the user is not logged in (like status, admin status, locale, ...).
So, in order to get the User ID you have to authorize the user, i recommend the JavaScript SDK for this:
https://developers.facebook.com/docs/howtos/login/getting-started/
This is against the Facebook Page Terms.
You can not have a contest where sharing is considered a entry in a contest.
Follow this link and look at Section III.E.3 for details
https://www.facebook.com/page_guidelines.php

Show content on external website, only if user is a 'fan' of the URL?

Similar to the ever-trendy Fan Page trick that allows page owners to only show certain content when a user performs the 'like' action (visible-to-connection), I wish to be able to only show certain content on a website once a user has liked the website.
If there is no FB code for this, I have considered using a Facebook like callback (triggered when a user likes on the current page) to set a cookie that establishes a user has liked the page or perhaps a database table that sets a users status to 'liked', again using the callback within the documentation.
Any ideas would be helpful. Thanks.
I haven't seen a "fangate" implementation for non-Facebook pages that didn't require you to go through the full Facebook authentication process (with the user_likes scope) first. You could set a cookie when they like, but that'll only work if they liked it via your site (i.e. if they liked you on Facebook, it wouldn't get caught by your site), and the cookie could get deleted or lost.
you can use the Javascipt SDK to easily accomplish this.
First, call FB.init:
https://developers.facebook.com/docs/reference/javascript/FB.init/
Then call getLoginStatus:
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
If they're not logged in ( not authorized your app ), then call
FB.login and then recall getLoginStatus.
If logged in, then get the user's likes via FQL:
https://developers.facebook.com/docs/reference/javascript/FB.Data.query/

Information about user how liked my page/group

After a user clicked on a "like" button of a facebook group or facebook page is it possible to get any addional information about the user beside name and uid?
I know with an app I can request access to a lot of data but I don't want to do that. I also know about facebook statistics.
The question targets more at the point if I publish any information about me if I like something.
The user ID isn't included in the callback on the edge.create event when a user clicks like, so the page doesn't get it then.
If you get a user ID via the user authorising your app you can access their public information at https://graph.facebook.com/ but you'll need them to allow additional permissions to see anything which wouldn't be accessible to a logged-out user.

Facebook requests - how to pass through custom variables from the Requests page

I am building a facebook app that has a send to friend feature in it.
Each user is given a specific userkey that identifies them and them alone.
So Person A invites person B.
So when person B gets the invite, when they click ACCEPT, we pass the referrer userkey in the URL…
e.g. http://mydomain.com.au/return_user.aspx?referrerkey=iuahsduiahsdfuiha
So when person B has already installed the fb app, the referrerkey variables is passed back to our site, so we can manage the link between the 2 users there.
However if person B hasn’t added the app. And Person B clicks the ACCEPT button on the invites page the user has to be take through the “Allow Access” page, from there, they are directed back to the APP home page, with none of the variables I need. E.g. the referrerkey.
So how can i get this to work for both users that have already added the app and havent added the app?
Yes, the request 2.0 flow will always land the user back on the canvas home page- no avoiding that.
When you create the request, though, you can add "data" parameter to the request object, and put whatever data in it you want. Then, on your canvas' home page, query for data in the signed_request. Setup a variable like, user_id or some app specific variable, game # or something. If it's present, then redirect to a more applicable page or route.
You can identify entries to your app- differentiating it by other non-request redirects to our canvas home page-- because there will be request_ids present in signed_request.
Note, you can also take the request id, and get the object from Facebook, which will have the "from" referrer. So you don't need to pass that around.
Assuming you're using the PHP facebook SDK and a canvas app, You're probably using require_login() to redirect the user to the auth screen. By default, the auth screen will send the user back to the canvas URL you set in the app settings.
To get around this, pass a GET parameter called "next" with a urlencoded URL as the value. If you're lucky, your version of the facebook SDK may have this code preset but not active. Look for ‘&next=‘ in the Facebook class.
The only option I know of is making adding the app and linking with friends two separate processes.