简体   繁体   English

JavaScript:喜欢使用Facebook javascript SDK的Facebook帖子吗?

[英]Javascript: like Facebook posts using facebook javascript sdk?

I'm fairly new in using Facebook javascript SDK and I have no idea what I am doing! 我在使用Facebook javascript SDK时还很陌生,我不知道自己在做什么!

I'm trying to like a facebook post using Facebook javascript SDk in my html page. 我想在我的HTML页面中使用Facebook javascript SDk喜欢Facebook帖子。

My full code this: 我的完整代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
 <script src='http://connect.facebook.net/en_US/all.js'></script>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>


<div  id="bod" style="width:100%; height:100px; background:#000;"></div>

<script>
$( "#bod" ).click(function() {


FB.api("/10153XXXXXXXXXX/likes", 'post',function(response) {
    if(response === true) {
         alert("done!");
    }
});
});
</script>
</body>
</html>

I thought this code will like the given post (its ID is 10153XXXXXXXXXX) once i click on the div #bod but when I click on the div, nothing happens and I don't even get the alert(); 我以为一旦我单击div #bod此代码就会喜欢给定的帖子(其ID为10153XXXXXXXXXX),但是当我单击div时,什么也没有发生,甚至没有得到alert(); at all! 都!

could someone please advise on this issue and let me know what I'm doing wrong? 有人可以就这个问题提出建议,让我知道我做错了吗?

First of all you'll need to initialize the FB SDK. 首先,您需要初始化FB SDK。

Then, in order to call the API you'll need a valid access token therefore, you'll need to login the user using your App. 然后,为了调用API,您将需要一个有效的访问令牌,因此,您需要使用您的App登录用户。

I would suggest to double check the docs again: https://developers.facebook.com/docs/javascript https://developers.facebook.com/docs/javascript/examples 我建议再次仔细检查文档: https : //developers.facebook.com/docs/javascript https://developers.facebook.com/docs/javascript/examples

In the second link you'll find an example to login a user and then call the API that I believe will be helpful for you. 在第二个链接中,您将找到一个登录用户然后调用该API的示例,我认为它将对您有所帮助。

I hope it helps. 希望对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM