Facebook like actions - Check if URL is liked - javascript

I've read the documentation about like actions, but can't get this to work.
I'm trying to get a status if a logged in user is liking an URL with the Javascript SDK. But doesn't get any progress.
How could this be done?
Below I use this code to "like" an URL.
FB.api(
'me/og.likes',
'post',
{
object: liked_url
},
function(response) {
// handle the response
}
);
HTML
<div class="like_button">Like This</div>
And when I click the above like button it likes the URL and add a class to the above div, but I want to be able to refresh the page and still have the "liked"-class on the objects that are liked.

I might have picked you up wrong but you could try using this to create your like button

Related

Call/load Jquery Page

I have a login screen which the user logs in using Jquery and AJAX. That's fine. Now what I want is that if the user logs in correctly, I want to load another page.
I tried using document.location = "home.html"; but that refreshes my page. What I want is like that transition that normally we have when we click on tag like
<a href="SchoolMaterials.html"> <!-- this does not refresh -->
I don't know if I explained myself clearly.
Thanks
It will be better to load the page in your callback function of successful login with:
$("#the_div_container_for_new_page").load("SchoolMaterials.html")
UPDATED:
it is something like this:
$(document).ready() {
function login() {
//post with ajax to login
$.post(......, function(result){
if (result.success) {
// load some page after successful login.
$('#id_of_container_div').load("thepage.html");
return;
} else {
// handle error
}
})
}
}
window.location is just what you need. You can also create an anchor element using jQuery and simulate a click on it :
$("<a href='your url'></a>").click();
But i wouldn't recommend that, it's better to post your data to the server and redirect to the page you want.

How to connect facebook send button with facebook UI?

After loading FB UI this is my Code:
<div class="fb-send" data-href="https://www.gmx.de" data-colorscheme="light"></div>
Now I want to add 2 different users (prefilled in the dialog).
There is code like this:
FB.ui({
method: "send",
link: "http://www.google.com/",
to: ["zuck","dmp"]
},
function(response) { alert(response); }
);
But how can I connect the Facebook-Button with this code?!
You are using Send Button and Send Dialog both- which isnt required! Both do almost the same thing.
I think you thought that you could pre-fill the recipients using the to parameter - that's right BUT you cannot add more than one recipient. You can use to with one user-id only.
On click of a button / html element- call FB.ui method, this will open the send dialog.

FB Open Graph script with default 'Watch' action does not work

//Update:
With help I managed to catch some errors which fixed the token issue. I've updated the code to reflect that. The code still doesn't produce an event on the timeline though so I'm leaving the question up.
Original question:
I'm trying to build a simple script using the Open Graph API that will push a link to a visited page (containing a movie) to Facebook, once the visitor hits the page.
I'm not using a custom action and object, but the standard Watch action (https://developers.facebook.com/docs/opengraph/video/) and Video.movie object.
I came up with this based on FB's example code:
<!-- first login-button with scope publish_actions: -->
<fb:login-button show-faces="false" width="200" max-rows="1" scope="publish_actions" ></fb:login-button>
<!-- Then script that should push update to timeline: -->
<script type="text/javascript">
function fbPublish(){
FB.api(
'/me/video.watches',
'post',
{ 'video.movie': '<?php the_permalink(); ?>',
'access_token': 'blablabla' },
function(response) {
if (!response || response.error) {
alert('Nope.');
} else {
alert('Yes.'); // any stuff
}
});
}
This triggers the alert 'Nope'.
I have added the Watch action through curl.
Any ideas as to what could be going on?
You still need to FB.login before you can automatically post to the user's timeline.
FB.login(function(response) {
// Post the action
}, {scope: 'publish_actions'});
While I didn't check the validity of your actual code to post the action, you problem is that before you can do this, you'll need the user's permission. The publish_actions permission is the one you'll need but I think its already included in new Auth Dialogs. Just leave it there to be sure.
Do the FB.login code first, you'll get a popup "Allow" dialog, after that, is the time you can freely post in the user's wall. It's a part of the security, Facebook users wouldnt want you posting on their timeline without them knowing.

Depending on event-status show attending-button

I've built a check for current rsvp_status for an event and the currently logged in member. Now I'd like to show an I'm attending button depending on someone's status. I can work out the HTML for the different buttons depending on their RSVP-status, but what I'm not sure of is how to write someone's rsvp_status back into the Graph after clicking the "I'm attending" button... Can you guys give me a push in the right direction?
Thanks!
Steven
You can post back attending status, this requires two things:
you have to have the rsvp_event permission for that user, and
you have to call
FB.api(eventID+'/attending', 'post', function(resp) { // true if the rsvp was successfull })
This will check the user in the event.
For more info, see Graph API

URL change ajax call in Facebook

In facebook, whenever you navigate to a different URL (in some situations), the URL changes but there is no feeling sensed as going to a different page.
For example: when we view pictures in facebook, and when we move to the next image the URL changes in the address bar
FROM >facebook.com/foo?bar=foobar&xxxx=
TO > >>facebook.com/foo?bar=boobar&xxxx=
and this is not hashed change also
like
FROM >facebook.com/xxxxx#xxx=xxxx
TO > >>facebook.com/xxxxx#xxx=yyyy
How is this possible seamlessly. I mean how is that only a container is modified on URL change. URL change is supposed to navigate to a different page which can contain cached information from previous page and THIS navigation by URL change can be seen obviously by browser's screen going blank for a moment.
If using an iFrame, how to implement this ?
I use somehting similar to this
try {
var stateObj = { foo: "bar" };
history.pushState(stateObj, "page", href);
loadPage(href);
}
catch(e) {
window.location.hash = "#!/"+href;
}
If it supports the HTML5 pushState them change URL, but if it doesn't then the fall back is the window hash.
wow. I just asked it few minutes ago ... use search next time ;)
Dynamic favicon when I'm proccessing ajax data
Modify the URL without reloading the page
There's a jQuery plugin called "address" that will watch for changes and call the function you give. I think it's just checking the URL every 100ms or so.
They issue an AJAX request for the data necessary to fulfil the "navigation", then tell the browser to "go to #xxx=yyy". Since such an anchor doesn't exist, the browser doesn't actually scroll down. However, it does record a new history entry, and also updates the URL so that if someone copy-pastes that URL, they will view the same object that the user is seeing, rather than just the original page.

Categories