简体   繁体   English

Facebook Api登录$ user的返回错误

[英]Trouble with Facebook Api login $user is not returning properly

When I run this code, and my cookies have been cleared and I am not logged into facebook. 当我运行此代码时,我的cookie已经清除,并且我没有登录到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... 它将我定向到facebook,然后我登录,但是当它带我回到我的页面时,它是相同的,应该在其中显示我的个人资料照片,等等。

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. 我似乎已经缩小了$ user的return语句的问题,因为它返回0。我盯着这段代码很长时间了,但我没有发现自己做错了什么。

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... 我需要做些什么才能使其得到更新,以便当我从Facebook登录后返回时,它将显示个人资料图片,依此类推...

<?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. 我的DEMO应用程序遇到了同样的问题,一直运行到昨天。

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. 我认为问题仅在于PHP SDK,因此可能会在一段时间后解决。

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. 在base_facebook.php文件中,找到makeRequest()方法并检查以下行。

$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/ 可以在此处找到更多详细信息-http://net.tutsplus.com/tutorials/php/how-to-authenticate-your-users-with-facebook-connect/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM