简体   繁体   English

如何在JavaScript中自定义Facebook OAuth对话框?

[英]How can I customize facebook oauth dialog in javascript?

I would like to change the location of the page url and I would strongly prefer to have the permissions request dialog open in a separate window. 我想更改页面URL的位置,并且我强烈希望在单独的窗口中打开权限请求对话框。

This is the JavaScript im using: 这是JavaScript im使用:

  <script>
        window.fbAsyncInit = function() {
  FB.init({
    appId      : 'XXXXXXXXXXXXXXX',
    status     : true, 
    cookie     : true,
    xfbml      : true
  });
};
    (function(d){
   var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   d.getElementsByTagName('head')[0].appendChild(js);
 }(document));
  </script>

The dialog that comes up in a separate window doesn't show up in all browsers, freaking IE... 单独的窗口中显示的对话框并非在所有浏览器中都显示,这使IE浏览器...

PHP: PHP:

 // Create our Application instance (replace this with your appId and secret).
    $facebook = new Facebook(array(
      'appId'  => 'XXXXXXXXXXXXXXXXXXXXXXXXX',
      'secret' => 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX',
    ));

    // Get User ID
    $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) {
        error_log($e);
        $user = null;
      }
    }

    //  n or logout url will be needed depending on current user state.
    if ($user) {
      $logoutUrl = $facebook->getLogoutUrl();
    } else {
      $loginUrl = $facebook->getLoginUrl(   array(
           'scope' => 'publish_stream,user_birthday,email,offline_access',
           'next'  => 'LINK HERE',
          ));
    }

Instead of attempting to subvert Facebook's JavaScript SDK, simply use the standard OAuth authentication, which allows you to redirect the user to an authentication or permissions dialog without a JavaScript popup. 无需尝试颠覆Facebook的JavaScript SDK,只需使用标准的OAuth身份验证,该身份验证可让您将用户重定向到身份验证或权限对话框,而不会弹出JavaScript。

See the Server-Side Flow section of the Authentication documentation and the Direct URL Example in the OAuth dialog's documentation . 请参阅身份验证文档服务器端流程部分和OAuth对话框文档中直接URL示例 Note that the example URL in the latter documentation looks extremely similar to your second screenshot. 请注意,后一文档中的示例URL看起来与第二个屏幕截图极为相似。

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

相关问题 不直接使用OAuth对话框时,如何从服务器facebook api调整facebook登录名的显示? - How can I adjust the display of a facebook login from my server facebook api when it is not using the OAuth Dialog directly? 如何自定义此javascript函数? - How can I customize this javascript function? JavaScript如何在删除对话框中实现此目的 - JavaScript How Can I achive this in delete dialog 如何将 Chrome Javascript 控制台中的默认缩进自定义为 2 个空格? - How can I customize the default indent in the Chrome Javascript console to be 2 spaces? 如何处理 javascript 中过期的 Facebook oauth 令牌 - How to handle expired Facebook oauth tokens in javascript 用户离开或刷新页面时如何自定义对话框消息 - How can I customize the dialog box message when user leaving or refreshing the for page 如何从 OAuth facebook nodejs 获取生日? (我可以在终端中登录但无法访问它) - How can I Get birthday from OAuth facebook nodejs? (I can log it in the terminal but can't access it) 如何使用JavaScript重新填充Facebook共享对话框 - How to repopulate Facebook Sharing Dialog with javascript 如何自定义对话框的宽度? - How to customize dialog width? Javascript 提示对话框自定义输入 - Javascript Prompt dialog customize input
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM