简体   繁体   English

Facebook Like Button不起作用

[英]Facebook Like Button doesn't work

First sorry for my nooby questions, i've checked almost everywhere but i couln't the right answer. 首先,我对我的nooby问题感到抱歉,我已经检查了几乎所有地方,但我找不到正确的答案。 There are lot of documents and tutorials but in development its changing. 有许多文档和教程,但是在发展中正在发生变化。 However, my problem is, i have a fan page that has a Tab which is integrated with my app. 但是,我的问题是,我有一个风扇页面,该页面具有与应用程序集成的选项卡。

I just want to check sessions that users was here and they already liked before or if they are already liked my page i want to update sessions and get new access tokens then redirect them to my fluid canvas page(this is my second question btw. because landing page is in 810px page. after they like pages refreshing thmeself and its opening in fixed area again.) 我只想检查用户在这里的会话 ,他们之前曾经喜欢过它们,或者如果他们已经很喜欢我的页面,我想更新会话并获取新的访问令牌,然后将他们重定向到我的流畅画布页面(这是我的第二个问题,因为目标网页位于810像素页面。他们喜欢页面刷新后又重新在固定区域打开。)

Do i have to put FB.login button in to my landing page or is it better to ask user permissions when the apps page onloading. 我是否必须将FB.login按钮放入登录页面,还是在加载应用程序页面时询问用户权限更好。

my folder schema is like: 我的文件夹架构是这样的:

-appfolder
--tab - (landing page in fixed page)
--app - (app page in fluid canvas)
--css
--img
--js
--php-sdk
--index.php (check everything here and redirect in here with login attributes)
--config.php
--fbaccess.php
--fbin.php
--fbout.php

Landing page code : 着陆页代码:

<?php
    require 'php-sdk/facebook.php';

    $app_id = 'xxx';
    $app_secret = 'xxx';
    // Set
    $app_namespace = 'hangisienmeshur';
    $app_url = 'https://apps.facebook.com/' . $app_namespace . '/';
    $scope = 'email,publish_actions';

    // Init the Facebook SDK
    $facebook = new Facebook(array( 
         'appId'  => $app_id,
         'secret' => $app_secret,
    ));

    // Get the current user
    $user = $facebook->getUser();
?>

    <!DOCTYPE html>
    <html xmlns:fb="http://ogp.me/ns/fb#" xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Tropicana Main</title>
    <link href="css/normalize.css" rel="stylesheet" type="text/css" />
    <link href="css/main.css" rel="stylesheet" type="text/css" />
    </head>

    <body>

    <div id="fb-root"></div>

    <script type="text/javascript" src="http://connect.facebook.net/en_US/all.js"></script>
    <script>

      window.fbAsyncInit = function() {
        FB.init({
          appId      : 'xxx', // App ID
          channelUrl : 'http://www.xxx.com/app/xx/channel.php', // Channel File
          status     : true, // check login status
          cookie     : true, // enable cookies to allow the server to access the session
          xfbml      : true  // parse XFBML
        });

        // Additional initialization code here
        FB.Event.subscribe('edge.create',
            function(response) {
                window.location.href = 'https://apps.facebook.com/xxx/';
            }
        );
      };

      // Load the SDK Asynchronously
      (function(d){
         var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
         if (d.getElementById(id)) {return;}
         js = d.createElement('script'); js.id = id; js.async = true;
         js.src = "//connect.facebook.net/en_US/all.js";
         ref.parentNode.insertBefore(js, ref);
       }(document));


    </script>



    <div id="mainfoto">
    <div id="fb_button" class="myClass rtl">

    <fb:like href="http://www.facebook.com/xxx" width="100" layout="button_count" show_faces="false" send="false"></fb:like>

</div>
</div>

</body>
</html>

Try to avoid the use of sessions in a Facebook app. 尝试避免在Facebook应用中使用会话。 Facebook loads your webpage in an iframe, which some browsers (Safari in particular) wont work properly with, due to security restrictions. Facebook会将您的网页加载到iframe中,由于安全限制,某些浏览器(尤其是Safari)无法正常使用。

Facebook recommends to wait with permissions until they're become necessary. Facebook建议等待许可,直到有必要。 You could request the permissions on canvas-load. 您可以请求canvas-load的权限。 Best usecase would be to wait for the user to do an action which requires their information (for example, clicks a "Signup" button). 最好的用例是等待用户执行需要其信息的操作(例如,单击“注册”按钮)。

For your flow to work, I would suggest this approach. 为了使您的工作正常进行,我建议您采用这种方法。

On the landingpage, use signed request to tell if the user has liked your page. 登录页面上,使用签名的请求来判断用户是否喜欢您的页面。

$signed = parse_signed_request($_REQUEST['signed_request'], 'YOUR-APP-SECRET');
if ($signed['page']['liked'] == 1) {
    $fan = true;
} else {
    $fan = false;
}

if ($fan)
{
    echo "window.location.href = 'https://apps.facebook.com/xxx/';";
}
else
{
     echo "<p>Please like the page.</p>";
}

( source ) 来源

This will redirect users who has liked your page, to the canvas page. 这会将喜欢您页面的用户重定向到画布页面。 Users who hasn't, will see the message "Please like the page". 没有的用户将看到消息“请喜欢该页面”。

You dont need to subscribe to 'edge.create', as a click on the "Like" button, will force a page reload and your code will then do the redirect since the user now likes the page. 您不需要订阅“ edge.create”,因为单击“赞”按钮将强制重新加载页面,并且由于用户现在喜欢该页面,因此您的代码将进行重定向。

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

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