-1

我正在努力寻找一种方法来检测用户是否未连接到我的应用程序,我想向活动“查看”发送一个“项目”,它工作得很好,但他们必须先单击登录链接,然后重新加载该页面,他们已登录。

我怎样才能让它自动发生?如何检查用户是否连接到应用程序?我尝试了以下代码,但未连接的用户只会得到一个空白页。

$facebook = new Facebook($config);
$user_id = $facebook->getUser();

    // Check if logged in
    if($user_id) {
            $params = array(
              'ok_session' => 1, // Logged in and connected
              'no_user' => 2, // Logged out of facebook
              'no_session' => 3, // Logged in but not connected
            );
            $next_url = $facebook->getLoginStatusUrl($params);

            if($next_url == 2 || $next_url == 3){
                header('Location: '.$facebook->getLoginUrl(array('scope' => 'publish_stream')));
            }
        } else {
            // Not logged in
            header('Location: '.$facebook->getLoginUrl(array('scope' => 'publish_stream')));
    } 

似乎没有检查用户是否已连接的功能,所以我使用了该getLoginUrl功能。

$user_id由提供$user_id = $facebook->getUser();

4

1 回答 1

0

If we are talking canvas/page tab app here, then the info you’re looking for is in the signed_requestparameter your app gets passed on initial load.

If not – “outside” of Facebook the PHP SDK has no way of knowing if there’s a user visiting your page that has used your app before if there aren’t any cookies set for your domain remaining that say so.

You can use FB.getLoginStatus out of the JS SDK – that will make a cross-domain request to Facebook to see if the user is logged in, and can set the appropriate cookies under your domain that’ll let the PHP SDK take notice on the next request to your server as well.

于 2012-08-15T15:29:49.147 回答