简体   繁体   English

Facebook“点赞”按钮回调帮助

[英]Facebook “Like” button callback help

I am using this code for facebook like callback:我正在将此代码用于 facebook 之类的回调:

           <script type="text/javascript">
                FB.Event.subscribe('edge.create', function(response) {
                  // php script to call via ajax
                });
           </script>

The problem is that if i call a php script (for example http://www.test.com/addfacebook?id=xx&user=xxx&code=xxxx ) someone can see my javascript and run this page and even spam it or use it without have liked first.问题是,如果我调用 php 脚本(例如http://www.test.com/addfacebook?id=xx&user=xxx&code=xxxx )有人可以看到我的 ZDE9B9ED78D7E2E1DCEEFFEE780E2F 或使用 1DCEEFFEE780E2F 并运行它有先喜欢。

The concept is that i want to give a unique special discount code to every user likes the page.这个概念是我想为每个喜欢该页面的用户提供一个独特的特殊折扣代码。 So on callback I want to store in database and id, the user real name from facebook and the discount code I created for him.因此,在回调时,我想将 facebook 中的用户真实姓名和我为他创建的折扣代码存储在数据库和 ID 中。

How to do it so someone can't override it (as it is javascript)?怎么做才能让别人无法覆盖它(因为它是javascript)?

Thanks a lot!非常感谢!

The easiest way to get at what you are doing is to verify the user is legitimate.了解您正在做的事情的最简单方法是验证用户是否合法。 I would have your ajax action have parameters that include the FacebookID and the access_token.我会让您的 ajax 操作具有包含 FacebookID 和 access_token 的参数。 This will prevent anyone from gaming your system.这将防止任何人玩弄您的系统。

Since you are using the FB JS SDK - just make a call to the API like so:由于您使用的是 FB JS SDK - 只需像这样调用 API :

FB.getLoginStatus(function (loginResponse) {
            FB.api('/me', function (graph) {
                var token = loginResponse.session.access_token;
                var fbid = loginResponse.session.uid;
        } else {
            // no user session available, someone you dont know
        }
    });

I'd put this in your FB.Event.subscribe and use the token and fbid vars accordingly.我会把它放在你的 FB.Event.subscribe 中,并相应地使用令牌和 fbid 变量。

Hope this helps!希望这可以帮助!

You can use the PHP SDK to verify the token Joey mentioned, once you have the token on the server use something like this:您可以使用 PHP SDK 来验证 Joey 提到的令牌,一旦您在服务器上拥有令牌,请使用以下内容:

$facebook = new Facebook(); // Replace the line with the call that sets the app id and secret
$user = $facebook->api('/me',array('access_token',$_GET['access_token']));

Then check the value in $user然后检查 $user 中的值

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

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