0

所以,我知道有很多类似的话题,我已经阅读了大部分,但仍然找不到答案。这是问题所在:我在 localhost 上使用了 facebook PHP SDK 授权,它工作得非常好。getUser() 函数返回 id,我可以检索用户信息。然后我搬到了一个实际的域,复制了工作代码,编辑了 facebook 应用程序设置,在 getLoginUrl() 函数的参数数组中编辑了 redirect_uri。现在我仍然可以通过这个应用程序登录,我被要求访问我的数据的权限,但 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';
}
4

0 回答 0