I wonder if there is a way to create a facebook like button that clicks when you short a particular post on face book and record in my database oo his name from the user, or by clicking the button like accomplishes two functions, one on facebook and one in my database.
Add a class or id to your facebook like button using jquery and using a click function as josaphatv mentioned trigger a callback function to your database using AJAX to save the information you needed.
You can use the Facebook Like button plugin which lets you give it a Javascript callback. You can link this callback to your database using AJAX.
Edit:
You asked for an example.
First you write a javascript function in the global scope. This is the function that you want to do stuff when somebody clicks the like button. Say you declared it like this:
function logFacebookLike(response) {
// AJAX to log to database
}
Now, at some point after you've loaded the button, you subscribe to the Facebook edge.create event and give it your callback. Facebook will run your function and pass in some data (as the response variable). You can subscribe to the event like this:
FB.Event.subscribe('edge.create', logFacebookLike);
That's it. You can learn more in the Facebook Javascript Documentation. If you wanted an example of the AJAX, then you need to create a different question with a more specific context.
Related
How do I set a facebook pixel event to track registration completion when my registration form completion redirects to my index page not to a registration success page?
Should I use a standard event or a custom event to achieve this, or, do I have to create an intermediate page that the registration form directs to and then redirects to index page?
Fire the Facebook Pixel event when the user clicks on the form submit with 'click' event listener. Standard versus Custom events is a separate issue, but I suggest sticking with Standard events where you can.
https://developers.facebook.com/docs/facebook-pixel/advanced/
Stephen, you provided too few information.
Richy is right that in your case if you can't control where your user lands after submitting the form you should use onClick event to send a pixel event. You can easily validate the form in the code of the onClick event and send it when you're sure data is according to your expectations. You can even do additional requests to your back-end to check the data.
If you can change how your web-site work you can make a landing page where you'd fire an event if all the processing went right.
If you can also easily do it on your index page by loading it with some parameter in the URL that indicates it is visited after the form was submitted. There you can have a simple JS code snipped with condition in it to fire a pixel event if URL parameter is present or do it with Google Tag manager which is even simpler.
There are a couple of good standard events you can use like Subscribe or Submit Application, review them here: https://developers.facebook.com/docs/facebook-pixel/reference#standard-events
You have countless options depending on what level of changes you can do to the site, you coding skills, CMS you use and precision you need.
i am trying to make the custom fb like button in angular js. So that i can call service to save some data for analytics purpose.we have to keep the track of the number of like of my page in our database.
I'm trying to use Facebook Like button in my Phonegap (HTML + JS) app, but it doesn't work.
If I test it in the browser (local test), the button appears.
But when I build it with Phonegap BUild and run it in my smartphone, the button is not showed.
I'm using the code below:
<div class="fb-like" data-href="https://www.facebook.com/pages/Save-Points/293951217439051" data-layout="standard" data-action="like" data-show-faces="true" data-share="true"></div>
The current way to implement the like action is by using the open graph object og.like - FB's documentation here. It's important to note that this method requires the publish_actions permission from the user. It's a bit of work to get this all running smoothly, but it is possible.
The phonegap-facebook-plugin has provided a guide here. Below are the instructions with some of my comments:
Your like button must not be the same (graphically) as the Facebook like button
This means no "thumbs up" symbol - quite a frustration!
When you display your page / button you have to call the getLoginStatus method first to know if the current user is connected to its Facebook account. If he is connected then call GET https://graph.facebook.com/me/og.likes?access_token=FB_ACCESS_TOKEN&object=URL_TO_LIKE with the Facebook Access Token returned by the g3. etAccessToken method (if this returns data then style your like button with a red heart for example, a grey heart if the call returns an empty array).
Along with checking a user is logged in, to reiterate you must check your app has publish_actions permission for the user. Though you could possibly request this upon the Like action.
Also, the array is in the data property of the response object. If you're checking as to whether the user has liked this URL, you'll basically want to check response.data.length > 0.
To create a like (when your user clicks on your like button and your like button is a grey heart) do a POST on https://graph.facebook.com/me/og.likes?access_token=FB_ACCESS_TOKEN&object=URL_TO_LIKE NOTE: You must have publish_actions permission to do this
After doing this, the URL has been successfully liked by the user, and now the GET method will return an array with one object. Calling this when the user already has liked the URL will result in an error.
To remove a like (when your user clicks on your like button and your like button is a red heart) do a DELETE on https://graph.facebook.com/LIKE_IDENTIFIER?access_token=FB_ACCESS_TOKEN. The LIKE_IDENTIFIER is returned from steps 2 or 3.
The unlike (DELETE) method is different to the rest - it's not based off /me, and instead of filtering via URL, you use the like id. You'll likely have to call the previously described GET method to get the ID (do response.data[0].id).
I have a music app that I developed using HTML5's canvas. As different songs are selected, I have jquery that dynamically updates the URL in the browser to point to the correct song. I also have jquery that updates fb:like element. By using the debugging tool, I'm able to cache the pages (since my server is able to return correct meta-data for each URL provided).
When I do this and like something on my website, I end up with a message saying "Sami liked a page." with some info underneath.
Next, I use the Open Graph curl commands to add a Recommend action (something I've created) to a given URL from my website. Now, when I like the same url, I end up with a message saying "Sami recommends this link" with some info underneath.
What I'd really like to do is have this message display "Sami recommends a song on website", which is what the message looks like when I look at the preview for my Song object in the Open Graph. Is there any way to do this?
Best,Sami
EDIT: probably good to note that I'm also getting some extra meta info from the website (such as og:site_name), but that this stuff is not being saved into the Actions portion of my Open Graph (as in I can't view that info using the Open Graph link to view my current Recommendations), though I can see it using the debugger tool.
The facebook like button "triggers" the most generic action which is the like, you can how ever change the like button to use "recommend" instead of "like".
In the documentation for the like button, in the attributes table you can see the "action" attribute which is:
the verb to display on the button. Options: 'like', 'recommend'
Also when you "Get Like Button Code" thing you can select Verb to display.
If you want to use your own actions you'll need to define them in the app settings page as explained in the Define Actions guide.
I'm looking to integrate the "like" button into a website, but I'm a little confused with the information available on the web. I read this article, which was in another stackoverflow article, but have some questions: http://www.saschakimmel.com/2010/05/how-to-capture-clicks-on-the-facebook-like-button/.
I've setup a "Page" already in facebook, and from what I understand in the link above, you need to setup an "App" to get an API key. What I don't understand though is that if I use this API Key, it's going to be pointing to my newly created "App", which has no fan base. How do I link this API Key, (or setup another key through the page admin), so I can have users "like" the real facebook page?
I want to run some javascript functions the moment a user likes the page, but I'm also a little confused on what API functions call, and whether these return a true/false value? I only really want to run these js functions if the user has not already liked the page..
Hope this all makes sense, would love any explanations you have to offer to point me in the right direction.
BUMP
after making a page and registering for it on face book, you will get a link, o trough the process again. Then just paste this link on your web site and you will get the like box. Paste it in a div tag.
You can also make a function in js which calls this like box and on its dependency you can call other js functions also.
//js code
function js()
{
create element div;
}
function other()
{
js();
}
If you just want an like button in your page , go to http://developers.facebook.com/docs/reference/plugins/like/
paste your fb page url in "URL to Like (?)" text box
get the code
paste in the div box of ur web site source code where you want it to appear