Creating "Like" buttons for arbitrary elements on my site, and reading back the status - possible?
Asked Answered
I

1

7

I'm a total newbie to Facebook programming and would like to know, as a follow-up to this question, whether the following is possible.

I have a collection of events on a web site. I'm fetching them from several RSS feeds, and have total freedom in how to output them - e.g. as single pages, so there is a permalink for every event.

I would like to

  1. Create a Facebook "like" button for each of the events without entering them into the Facebook system in any way

  2. Read back the "like" status of the current user for any one of those events via JavaScript or on server side so I can display these events in a "events I like" list. The important thing is that I need to be able to read the status later = on subsequent page requests, not only in the moment the user clicks the "like" button.

@karim79's answer does answer the first part, but not the second yet.

this page contains all the information I need to create the button: Social plugins > Like button there also is an FBML event to react to when somebody signs up. But that still doesn't enable me to check the "like" status of a returning user.

Is there any way to do that?

Itself answered 19/8, 2010 at 10:41 Comment(4)
(related) openlike.orgPessimism
I'm a bit confused about your second point: 'Read back the "like" status of the current user for any one of those events'. Is your intention simply to indicate to the user that he/she has already 'liked' it?Hovey
@Hovey I'd like to misuse the "like" function as a kind of external storage system, and show those of the events that the user has marked as "liked" in a separate list on my site ("upcoming events you have marked as interesting"). It's conceivable that this is not possible due to privacy issues, though - I don't know.Itself
I'm not sure if you're able to get the like status from FaceBook. What first comes to my mind is to use a javascript onclick event to store in a database whenever a user clicks one of the like buttons.Destruct
H
13

A brain-dead way of automatically generating 'like' links for your site (which I recently implemented - so I know works) would be to simply generate the 'href' parameter which (facebook's) like.php reads from the iframe source. Just build the iframe code using their widget thingie and use PHP to dynamificate the href parameter:

<iframe src="http://www.facebook.com/plugins/like.php?href=<?php echo urlencode($url); ?>%2F&amp;layout=button_count&amp;show_faces=false&amp;width=50&amp;action=like&amp;colorscheme=light&amp;height=21" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:75px; height:21px;" allowTransparency="true"></iframe>

You can customise it to a limited extent, just see the attributes list right under the button creation widget.

Using fbml (which I was too lazy to incorporate, and somewhat reluctant due to the fact that I would have had to include yet-another-library):

<fb:like width="200" show_faces="no" href="<?php echo $url; ?>"></fb:like>

There's a neat list of examples here: http://fbrell.com/xfbml/fb:like

Hovey answered 19/8, 2010 at 11:36 Comment(5)
Cheers, I like brain-dead ways :) This is good to know for the creating part.Itself
@Itself - for the second part, I think you will need to mess with FB.Event.subscribe to hook to the edge.create event (developers.facebook.com/docs/reference/javascript/…) in conjunction with some JS to store current user/clicked eventID to your database, but I'm not sure how exactly at this point in time. I'm working on it as I could use this :)Hovey
@karim thanks for the info! That looks like a viable option. I won't be able to work on this today - if you manage to find more details, I'd be grateful for an update.Itself
Awarding the bounty: Catching the onclick event seems in fact to be the only way to do this - which is sadly not enough for me, because I have nowhere to store that status in. But, it doesn't seem possible to do any other way!Itself
@Itself - Hoooray! My first bounty! <opens a beer> :)Hovey

© 2022 - 2024 — McMap. All rights reserved.