Facebook php sdk适用于localhost但不适用于其他服务器

时间:2013-10-13 16:12:12

标签: php facebook magento

所以,我知道有很多类似的话题,我已经阅读了大部分内容,但仍然无法找到答案。 这是问题所在:我在localhost上使用了facebook PHP SDK授权,它工作得很好。 getUser()函数返回了id,我可以检索用户信息。然后我移动到一个实际的域,复制了工作代码,eddited facebook app设置,在参数数组中编辑了redirect_uri for getLoginUrl()函数。现在我仍然可以通过这个应用程序登录,我被要求获得访问我的数据的权限,但getUser()返回0。 我在magento上运行它,这是代码:

public function facebook_main($controller_name) {
    $appid = $this -> getAppId();
    $secretid = $this -> getSecretId();
    $facebook = $this -> facebook_config($appid, $secretid);
    $user = $this -> get_user($facebook);
    if (!$user) {
        return $this -> get_login_url($facebook, $controller_name);
    } else {
        $user_profile = $facebook->api('/me','GET');
        $facebook -> destroySession();
        return $user_profile;
    }
}

function getAppId() {
    return Mage::getStoreConfig('social/fb/appid');
}

function getSecretId() {
    return Mage::getStoreConfig('social/fb/secretid');
}

function get_user($facebook) {
    return $facebook -> getUser();
}

function facebook_config($appid, $secretid) {
    require_once "fb_include/facebook.php";
    $facebook = new Facebook( array('appId' => $appid, 'secret' => $secretid, 'cookie' => true));
    return $facebook;
}

function get_login_url($facebook, $controller_name) {
    $redirect_uri = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
    $scope = $this -> set_scope();
    $params = array('scope' => $scope, 'redirect_uri' => $redirect_uri . "/index.php/socialintegration/".$controller_name."/fb");
    $loginUrl = $facebook -> getLoginUrl($params);
    $img_url = $redirect_uri."app/code/community/Cheesecake/SocialIntegration/Model/button_images/fb.png";
    return "<a href=" . $loginUrl . "><img src=".$img_url." style='width: 40px'></a>";
}

function set_scope() {
    return 'email,user_about_me, read_stream, friends_likes';
}

0 个答案:

没有答案