I want to display a different message if a user is currently logged in to facebook and likes the current page. I understand:
FB.Event.subscribe('edge.create', function(response) {
// you like this
});
Which will fire when a user likes the page, but when you reload the page how do you determine they already like the current page?
Thanks!
I'm pretty sure you cant do what you want (in this context).
Take a look at this page : http://fbrell.com/fb.api/does-like
You'll see you need the user to approve a permission to view the likes.
It's a huge security risk to allow someone to see the 'likes' of a user - even for the current page. Think about it you can easily spoof the current page and pretend to be any page.
BUT...
What I recommend you do is just set a cookie for your own benefit (in javascript) when the user 'Likes' your page. Assuming you're getting a large percentage of your 'Likes' from this page then you can safely correlate the presence of the cookie with a 'Like'.
I've seen some security exceptions doing this, but it seems to work (at least in Chrome).
Sense you describe the page as "current page" I understand that it is in an iframe tab. If this is the case, signed request supplies you with that information as $decode_signed_request = array('page' => array('liked' => true/false)).
Otherwise you can supply a canvas page with the GET parameters fb_page_id, which should include the parameter fb_sig_added to the server request with a 0/1 depending on if the user is a fan of that page. (This may require disabling OAuth 2.0 in your migration settings)
If you are talking about the like social plugin with an open graph url, you can not readily find out if the user is a fan without an application installation. If you do have that you can do an api call to /me/likes which will return a list of all the likes that user has, and search for the id of the object you are testing for.
You're safer using the Graph API since Facebook is in the process of deprecating their REST API. So to get if a user likes your page, you will need the page ID and the access token of your app.
https://graph.facebook.com/me/likes/PAGE_ID?format=json&access_token=ACCESS_TOKEN
Where PAGE_ID is the page id you want to check.
and ACCESS_TOKEN is your apps access token.
From the Graph API you can get the likes of a user by his id, as:
https://graph.facebook.com/ID/CONNECTION_TYPE
so for getting the likes you put your access token and:
https://graph.facebook.com/me/likes?access_token=2222222222222222
then look for your page if it is liked or not.
However you can always try FQL queries which i didnt try for Likes actually.
I hope that helped.
save user id or third_party_id in database when the user liked the link
to Get third_party_id
graph.facebook.com/me/?fields=third_party_id&access_token=xxx
https://graph.facebook.com/{FB_USER_ID}?fields=likes.target_id(167584559969748)&access_token={VALID_ACCESS_TOKEN}
shows data if that user has liked that Facebook fan page.
or
https://graph.facebook.com/{FB_USER_ID}?fields=likes.fields(link)
shows a list of liked links, from where you can get the link you are looking for.
All of these need 'user_likes' and/or friend_likes permissions.
Related
I'm relatively certain after reading the facebook Open Graph documentation that I can't have a web site 'subscripe' to a public page, unless that page installs my app. Let me know if that is wrong.
What I am trying to make is a photo gallery, pretty simple, but it grabs photos from a public 'page' such as a college or university.
I would like it to update itself anytime there is a change. I was hoping I could do it through the API, possibly using API updates/subscription
Facebook App Subscriptions -
but I don't think that will work. I'm using PHP, are there other ways to listen and see if there has been a change? Other than just firing off a function every now and then, using CRON or some other such server tool. I would think that facebook would probably also not like that behavior, though I'm not sure.
As of right now, I am able to grab JSON from a public page's photo gallery using the API and the photo gallery works just fine, I'm mostly just wondering what the optimal of having it update itself automatically is.
You are correct in assuming that real-time updates for pages require admin access to the page to work. You need a page access token to be able to subscribe to updates for a specific page, and such a page access token you can only get from users that have admin privileges for that page. (The page does not need to install your app as a tab any more, they changed the subscription process in that regard; but the page access token is still necessary. Basically you can say, you can not subscribe to updates for just any arbitrary page, it has to be “your” page.)
Apart from that, all you can do is check for new content by requesting the current data in a sensible interval.
you need to get page access token, which is granted when the user is one of the Page Admin, check the documentation on Facebook
https://developers.facebook.com/docs/graph-api/reference/page
look for this line
"access_token": "The access token you can use to act as the Page. Only visible to Page Admins"
OBJECTIVE: I need to display latest 5 entries from users timeline on website, using PHP.
Please not that i speak about timeline of user profile - not fan page, not group.
SO FAR I DID THIS:
Registered as Facebook developer
Registered app
Obtained token
Opened url: https://graph.facebook.com/USER_ID/feed?access_token=MY_TOKEN
Voila. Feed of that user is displayed now, but..
PROBLEM: So now i have users feed, but it looks like its partially working.
It happens often that it don't displays some updates, sometimes it displays just date of the post and not the content.
However when i try to grab feed from some facebook fan page, then everything work normal.
MY QUESTION: Are we allowed to grab user timeline? If yes, what im doing wrong?
You won't ever see all the information that is visible inside the Facebook app via the api. This comes from how Facebook filters out the data. See this Facebook Developers blog post for more information: https://developers.facebook.com/blog/post/478/
Yes you are allowed to to grab user timeline posts, even with a limit, if your app asks for read_stream permission. Issue an HTTP GET request to the below URL:
https://graph.facebook.com/user_id/posts?access_token=token&limit=5
I have a Fan Page and I need to post something on users Wall after clicking Like Button. Moreover I need to display different content for users who "Like" the page and for users who don't "Like" the page. Is there an application like "Static iFrame Tab" which already solves this? If not, then how to post something on users Wall? I downloaded the facebook.php file, but I haven't managed to find the required function there.
The user's 'like' status can relatively easily be returned by decoding the signed request sent by Facebook to the page.
I've built a simple fan/like gate that is available over on GitHub - it might help you get up and running.
With regards to posting to the user's wall. I would suggest using the Javascript SDK and reading the FB.ui documentation over on Facebook.
I am a bit of a catch 22 situation here.
When you load your app into a tab and ask for permission you need to send with it a callback url.
The callback url is a bit of a mission because on a page http://www.facebook.com/pages/<PAEG NAME>/<PAGE ID>?sk=app_<APP ID> the only way to get the <PAGE ID> is to get it out of the signed request:
parse_signed_request($_REQUEST['signed_request'], $APPSecret)
which you can only do when the user has given permission. And you need the ID to be able to get the <PAGE NAME>, which basically means I cannot construct the callback url...
Does anyone know of a better way or different way to Ask for permissions immediately as the page loads and then reload the page?
It seems that you are a bit confused, here are some points:
Your callback (redirect) url should be something relative (or identical) to the Tab url you specify in the application settings. Something like:
http://www.example.com/canvas/tab/index.php
So no need for the page id.
Even if the page id is not needed, you'll still receive it (even without authorization) in the signed_request!
Read the Facebook documentation related section carefully:
When a user selects your Page Tab, you
will received the signed_request
parameter with one additional
parameter, page. This parameter
contains a JSON object with an id (the
page id of the current page), admin
(if the user is a admin of the page),
and liked (if the user has liked the
page). As with a Canvas Page, you will
not receive all the user information
accessible to your app in the
signed_request until the user
authorizes your app.
So the thing that you'll not receive is the USER ID not the page id which is kind of obvious since the admin "allowed" the application.
Hope this will clear things out for you.
Use JavaScript SDK
http://developers.facebook.com/docs/reference/javascript/
And use this allow dialog
http://developers.facebook.com/docs/reference/javascript/FB.login/
This way you don't even need to refresh.
Also, you can get page_id in signed_request even without user allowing it. You're talking about user_id and oauth_token which won't get passed unless signed-in user doesn't allow your app.
I'm developing this Facebook Application and I was wondering if it's possible (and how) to programmatically, through the Facebook PHP Graph API, press some 'Like' button on some page?
Of course, this is optional on my application... I'm still not ready to really explain what application I'm doing, but it would be interesting to code such a feature.
Is it possible somehow?
By your description it sounds like you're trying to get a user to like something without the users knowingly clicking a like-button. This sort of interaction is not condoned by Facebook, I think. There are various black-hatty ways to accomplish this though, one fairly elaborate one is descriped here: http://www.liquidrhymes.com/2010/08/25/smoking-hot-bartender-is-some-smoking-hot-facebook-spam/
UPDATE Sorry, I might be wrong. If you get stream_publish extended permissions from the user, you might be able to like posts on their behalf by doing a POST to /POST_ID/likes. See Publishing to Facebook in http://developers.facebook.com/docs/api
You cannot do this. Facebok wont let you do a POST to /POST_ID/likes, you can only do a get request to retrieve their likes. What you are trying to do is a violation of facebook's TOS. I would suggest just adding a like button and "forcing" them to like before they continue with your application. However, in my opinion even that is kind of silly because they can instantly go unlike it after they have used your application.
i was looking for the same thing, but not to force a user into liking something, but actually for their own protection.
here is where i come from: on a web site (maybe on multiple pages) there is an "I Like" button, implemented as described by facebook.
each time a user goes to that page, the browser will make a request to facebook, throught the iframe that contains the button, providing all the info that we are used to from a web server log file.
if the user has in the past logged in facebook and not cleared the cache. the request will also contain the cookie indentifying the facebook user.
so even more then analytics, facebook know all about the user activity on those pages.
so i wanted the user to only give this info when they decide to.
my solution was to have a button (as graphic only) on the page. when the user clicks it a new frame should open and only there the facebook code should be executed.
obviously on the new frame i could not put the normal "i like" code, since that would require a 2nd click for the user. at this point i would need the "programmatically clicking of the i like button".
it is not an opengraph solution, but it works: the frame just does a redirect to
http://www.facebook.com/share.php?u=URL