perl Facebook::Graph API check if user likes page - facebook

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.

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.)

Posting to a Facebook page on behalf of page using a Facebook application by anyone

I have a web page linked to a Facebook application where users can log in by their Facebook account.
I have also a Facebook page for my application where anybody can post.
What I'd like to achieve is the following:
- An ordinary user logs in to my web page using her Facebook account,
- She adds an information to my web page (for example a book name),
- That information is instantly posted to my application Facebook page under page's name (for example "this book is read by someone").
I don't want it to be posted by the user, I don't want it to be posted by myself (admin of the page).
I don't want to mention about the user, it will be anonymous information.
But I couldn't find a way to do it either as JS or PHP.
Any suggestion is welcome.
Many thanks.
You will need to get a page access token. https://developers.facebook.com/docs/facebook-login/access-tokens/
Get it, store it somewhere on your server – and then use it when making the API call to post what the user entered.

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/

Check whether user of non-facebook app likes/shares particular URL on FB

I'd like to know if there is a possibility to check (using Graph API or any other way) whether given user likes / shares a specific link. Probably I'll have this user's facebook ID or facebook login, but my site is non-Facebook application. Actually it's Dot Net Nuke portal (target: .NET with MS SQL Server) with part of it being avaliable as Facebook app, but certainly not greater part of it, so the solution should be out of Facebook Connect, although it's not a showstopper if it's necessary.
We'll be giving points to users who share/like most of links that we serve in our portal and such possibility would be a great help to make a ranking.
Another option we consider is making some kind of "wrapper" or proxy for FB like / share buttons which will at first save some data in our database (probably - this user clicked on like for this link) and then go on with standard FB like / share route. Did anybody of You tried such solution?
If You have any other suggestion on the subject, please, post them, we'll be really thankful.
It is possible to know if a user has LIKED a site or not. You can get all user's likes with Graph API (you need user_likes permission). Take a look at the docs: http://developers.facebook.com/docs/reference/api/user/
I'm not sure if you can know if he has shared your site, but you could try by parsing his wall with the read_stream permission and then look for your site name/URL post by post.
For just general liking of items on your site, you can use a Facebook Social Plugin. However, you won't be able to associate (or really even access) user activity with users on your site without integrating Facebook Connect and creating a Facebook application for your site. At that point you can design with greater control all the possible user activity and interleave with your facebook calls other calls that affect users' accounts on your site.

Facebook page apps - Authorizing a user

I can't seem to find exactly what I'm looking for. We're trying to build an app to run solely on a Facebook Page. We want to show a landing page if they don't Like the page, and the contest entry form if they do. This functionality works.
Before showing the contest entry form, we'd like to authenticate the user viewing the app so that they can just hit "Enter the contest!" and we can automatically pull a name/email address.
Any of the methods of authentication I've seen described, including through the Facebook Developer docs, don't work at all.
I saw something that said they need to interact with the app first, then you can get the id, but that doesn't work either. I also don't get the page id passed with the signed request.
Its also pretty unclear whether I should be using an iframe or just FBML.
Could anyone point me in the right direction, please? Thanks!
You need to create a fan page and add the FBML plugin to that page, then you will need to insert a short code that will determine if a facebook user has clicked 'Like' or not and by determining that you will decide weather to display the content of the landing page or not (using an iframe). You will probably like to also set the FBML box that you create as the default view for members who didn't press the 'Like' button yet, you can change the default view in your fan page settings.
On the iframe, you will need to use the Facebook API if you want to retrieve any user information from Facebook, for that, you will need to register a new application with Facebook. Go to developers.facebook.com for the API integration and app registration.
Also, what do you mean when you say:
Any of the methods of authentication
I've seen described, including through
the Facebook Developer docs, don't
work at all.
Well, it appears you can't do it that way. The client was very specific in wanting that functionality but we ended up convincing them to go for a redirect to the canvas page to have the app authorized and the contest entered instead.