请求权限弹出窗口后,facebook 应用程序不会重新加载 - 使用 PHP SDK (v.3.1.1)

发布于 2024-12-21 17:50:44 字数 2013 浏览 1 评论 0原文

正如所指出的,我的旧 Facebook 应用程序需要更新到最新的 php sdk 在另一个问题中。我的下一个问题是让它与最新的 php sdk 3.1.1 一起工作

我正在使用最新的 php sdk ie 附带的示例; with_js_sdk.php

它工作正常,直到有人授予访问应用程序的权限,而不是重新加载用户 对于应用程序,它会让用户再次登录。如何将用户重定向到应用程序 成分。注意我有一个警报,它调用 window.location.reload();但之后它不会向用户显示 他添加了应用程序

代码如下:

<?php

require 'facebook.php';

$appCanvasPage = 'https://apps.facebook.com/myapp/';
$app_id = "";
$app_secret = "";


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

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

echo "user=".$user."\n";


?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>


    <h2> THIS IS MY APP </h2>    

    <?php } else { ?>

      <fb:login-button></fb:login-button>

    <?php } ?>

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });

        FB.Event.subscribe('auth.login', function(response) {
          alert(At reload);
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });

      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>

My old facebook application requires updating to the latest php sdk as was pointed out
in another question. My next problem is getting it to work with the latest php sdk 3.1.1

I'm using the example that comes with the latest php sdk ie; with_js_sdk.php

It works fine up until one gives permission to access the application but instead of reloading bringing the user
to the application it returns the user to the log in again. How do I get the user redirected to the application
component. Note I have an alert that it calls window.location.reload(); but it doesn't show the user after
he added the application

The code is below:

<?php

require 'facebook.php';

$appCanvasPage = 'https://apps.facebook.com/myapp/';
$app_id = "";
$app_secret = "";


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

// See if there is a user from a cookie
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    echo '<pre>'.htmlspecialchars(print_r($e, true)).'</pre>';
    $user = null;
  }
}

echo "user=".$user."\n";


?>
<!DOCTYPE html>
<html xmlns:fb="http://www.facebook.com/2008/fbml">
  <body>
    <?php if ($user) { ?>


    <h2> THIS IS MY APP </h2>    

    <?php } else { ?>

      <fb:login-button></fb:login-button>

    <?php } ?>

    <div id="fb-root"></div>
    <script>
      window.fbAsyncInit = function() {
        FB.init({
          appId: '<?php echo $facebook->getAppID() ?>',
          cookie: true,
          xfbml: true,
          oauth: true
        });

        FB.Event.subscribe('auth.login', function(response) {
          alert(At reload);
          window.location.reload();
        });
        FB.Event.subscribe('auth.logout', function(response) {
          window.location.reload();
        });

      };
      (function() {
        var e = document.createElement('script'); e.async = true;
        e.src = document.location.protocol +
          '//connect.facebook.net/en_US/all.js';
        document.getElementById('fb-root').appendChild(e);
      }());
    </script>
  </body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

迷爱 2024-12-28 17:50:44

我找到了一个简单的解决方案,无需使用 facebook 上的 sdk。

链接是:
https://developers.facebook.com/docs/appsonfacebook/tutorial/

<?php 

     $app_id = "YOUR_APP_ID";

     $canvas_page = "YOUR_CANVAS_PAGE_URL";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            echo ("Welcome User: " . $data["user_id"]);
     } 
?>

做了诡计。

大卫·J。

I found a simple solution without using the sdk which was on facebook.

the link is:
https://developers.facebook.com/docs/appsonfacebook/tutorial/

<?php 

     $app_id = "YOUR_APP_ID";

     $canvas_page = "YOUR_CANVAS_PAGE_URL";

     $auth_url = "https://www.facebook.com/dialog/oauth?client_id=" 
            . $app_id . "&redirect_uri=" . urlencode($canvas_page);

     $signed_request = $_REQUEST["signed_request"];

     list($encoded_sig, $payload) = explode('.', $signed_request, 2); 

     $data = json_decode(base64_decode(strtr($payload, '-_', '+/')), true);

     if (empty($data["user_id"])) {
            echo("<script> top.location.href='" . $auth_url . "'</script>");
     } else {
            echo ("Welcome User: " . $data["user_id"]);
     } 
?>

did the trick.

David j.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文