首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Facebook XFBML登录按钮阻止弹出

Facebook XFBML登录按钮阻止弹出
EN

Stack Overflow用户
提问于 2012-01-07 22:22:28
回答 2查看 522关注 0票数 0

说来话长

我目前在一个网站上工作,限制它的一些内容注册用户(用户,谁已经填写了注册表)和facebook用户(谁已经授权网站访问他们的信息)。我使用cookie来存储用户最后一次访问该站点时使用的登录类型。0代表“无登录”或“用户注销”,1代表“注册用户”,3代表"facebook用户“。如果facebook用户已经登录到他们的facebook帐户,我希望站点仅在cookie为"2“时才让用户登录(之前的登录是使用facebook登录完成的)。否则,我希望用户单击"facebook登录“按钮。默认情况下,它会打开一个弹出窗口,然后立即将其关闭。我如何才能防止弹出窗口显示出来,而是将用户发送到特定的URL?

对于那些不理解我杂乱无章的演讲或者只是想切中要害的人

我有一个脸书登录按钮(),而不是弹出,我需要它来重定向用户。

EN

回答 2

Stack Overflow用户

发布于 2012-01-07 23:15:47

使用FB.getLoginStatus() Javascript SDK函数检查用户的登录状态。请参阅:http://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/

票数 0
EN

Stack Overflow用户

发布于 2012-01-07 23:16:50

使用PHP-SDK:

代码语言:javascript
复制
<?php
require 'facebook.php'; # The SDK

# Create our Application instance (replace this with your appId and secret).
$facebook = new Facebook(array(
  'appId'  => 'APPID',
  'secret' => 'APPSECRET',
));
# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------

// Get User ID
$user = $facebook->getUser();

/* We may or may not have this data based on whether the user is logged in.
   If we have a $user id here, it means we know the user is logged into
   Facebook, but we don't know if the access token is valid. An access
   token is invalid if the user logged out of Facebook. */

if ($user) {
  try {
    # Proceed knowing you have a logged in user who's authenticated.
    $dt = $facebook->api('/me'); # User Data
    $lk = $facebook->api('/me/likes'); # User like's Data
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

# ----------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------
# Handler for Login Status
if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {

  # This is the User LogIn URL, and if the user hasn't already given your app the permissions this url will ask him/her for that.      

  # After the 'scope' is where the permission are written.

  $loginUrl = $facebook->getLoginUrl(array("scope" => "email,user_birthday,user_likes,user_work_history,user_location,user_education_history"));
}
# -------------------------------------------------------------------------------------
if (!$user): header ('Location:'.$loginUrl.''); # This is where we check if the user is logged in to facebook or not, if not, the user will be re-directed to the log in page.
    else: 
    # If the user is logged in, do some code...

    endif;
?>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/8770354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档