麻烦与Facebook API登录$用户没有返回正确 [英] Trouble with Facebook Api login $user is not returning properly

查看:156
本文介绍了麻烦与Facebook API登录$用户没有返回正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行这个code和我的饼干已被清除,我没有登录到Facebook上。它引导我到Facebook和我登录,但是当它带给我回到我的页面是一样的,在那里,它应该是给我的个人资料图片等等...

我似乎因为它返回一个0。我在这个code很长一段时间都盯着已经收窄$用户的return语句的问题,我还没有发现什么,我做错了。

我需要做什么改变来获得它,这样当我从从Facebook登录回到它会显示配置文件图片等...

 < PHPrequire_once'库/ facebook.php';
需要'连接/ connection.php';//创建我们的应用实例(与你的appid和秘密替换此)。
$ Facebook的=新的Facebook(阵列(
            APPID=> XXXXXXXXXXXXX',
            '秘密'=> XXXXXXXXXXXXXXXX',
        ));//获取用户ID
$ USER = $ facebook->的getUser();
回声$用户;如果($用户){
    尝试{
        //继续知道你有个登陆,谁是验证用户。
        $ USER_PROFILE = $ facebook-> API('/我');
        回声$用户;
    }赶上(FacebookApiException $ E){
        error_log中($ E);
        $ USER = NULL;
    }
}//登录或注销的URL会根据当前用户状态是必要的。
如果($用户){
    // $ logoutUrl = $ facebook-> getLogoutUrl();
    $ logoutUrl = $ facebook-> getLogoutUrl(阵列('下一个'=>($运行fbconfig ['baseURL时']'logout.php')));
}其他{
    $ STATUSURL = $ facebook-> getLoginStatusUrl();
    $ loginUrl = $ facebook-> getLoginUrl(阵列(
        范围=> user_about_me',
        范围=> read_friendlists
            ));
}
?>


解决方案

不用担心我的朋友,你是不是做错了什么。我在与这是昨天为止运行好吗我的演示应用程序相同的问题。

我敢肯定,您有获得访问令牌,以及问题。我认为问题是与PHP SDK only.So可能会固定在一定的时间。

解决方案:这为我工作努力为这个问题的解决方案,许多后

在base_facebook.php文件中,找到makeRequest的()方法,并检查是否有以下行。

  $ =选择采用自我:: $ CURL_OPTS;

紧随其后,加入这一行

  $选择采用[CURLOPT_SSL_VERIFYPEER] = FALSE;

更多细节可以在这里找到 - 的http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/

When I run this code, and my cookies have been cleared and I am not logged into facebook. It directs me to facebook and I log in but when it brings me back to my page it is the same, where as it should be show me profile pic and so on...

I seem to have narrowed down the problem of the return statement of the $user because it returns a 0. I have stared at this code for a long time and I havent found what I am doing wrong.

What do i need to change to get it so that When i return from logging in from facebook it will show the profile pic and so on...

<?php

require_once 'libs/facebook.php';
require 'connections/connection.php';

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

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

if ($user) {
    try {
        // Proceed knowing you have a logged in user who's authenticated.
        $user_profile = $facebook->api('/me');
        echo $user;
    } catch (FacebookApiException $e) {
        error_log($e);
        $user = null;
    }
}

// Login or logout url will be needed depending on current user state.
if ($user) {
    //$logoutUrl = $facebook->getLogoutUrl();
    $logoutUrl = $facebook->getLogoutUrl(array('next' => ($fbconfig['baseurl'] . 'logout.php')));
} else {
    $statusUrl = $facebook->getLoginStatusUrl();
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => 'user_about_me',
        'scope' => 'read_friendlists'
            ));
}
?>   

解决方案

Not to worry my friend, you are not doing anything wrong. I'm having same issue with my DEMO application which was running alright till yesterday.

I'm sure you are having issue with getting access token as well. I think issue is with PHP SDK only.So probably will be fixed in some time.

SOLUTION : This worked for me after trying for many solutions for this issue.

In base_facebook.php file, find the makeRequest() method and check for following Line.

$opts = self::$CURL_OPTS;  

Immediately following it, add this line

$opts[CURLOPT_SSL_VERIFYPEER] = false;  

More details can be found here - http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/

这篇关于麻烦与Facebook API登录$用户没有返回正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆