Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't seem to work at all with CI 2.0? #5

Open
kasperfilstrup opened this issue Feb 22, 2011 · 49 comments
Open

Doesn't seem to work at all with CI 2.0? #5

kasperfilstrup opened this issue Feb 22, 2011 · 49 comments

Comments

@kasperfilstrup
Copy link

Hi there,

I've really looking forward to trying out your Facebook-CodeIgniter integration, but it seems like it doesn't work. Isn't it possible to try it out while working on localhost if I just register my app on facebook with http://localhost/ as URL or is it required to be online on a real domain before it works?

The issue is that I can see the login link and when I click it, I sure enough gets redirected to Facebook for login and permission granting. When I get sent back to my app on localhost, it shows my FB picture and says I'm logged in. However, it still shows the "Login" link and not anything else. :-/

Any idea what I'm doing wrong or if it it's a bug with CI 2.0?

@JackWH
Copy link

JackWH commented Feb 22, 2011

This is exactly the same problem I'm having.

Running this code:

if(!this->facebook->logged_in())
{
    echo "Logged out";
}
else
{
    echo "Logged in";
}

will always tell you that you're logged out, whether or not you're logged in. Confusing huh...

I haven't tested it online so I wouldn't know if putting on a host (other than localhost) would make a difference. Are you running yours in MAMP? Wondering if it's a MAMP configuration thing possibly...

Also - I'm pretty confident it's not a CI 2.0 issue, as Elliot's docs say http://www.haughin.com/code/facebook/ it needs CodeIgniter Reactor - new to CI 2.0.

@kasperfilstrup
Copy link
Author

@JackWebbHeller
I'm running WAMP.

Annoying though that no error message is thrown :-/

@mdgrech23
I couldn't finde the code you mentioned in Elliots library, so I'm assuming it doesn't use the default PHP SDK... But have no clue since the installation guide is rather sparse, so if it's required then that might be my problem. :-)

@JackWH
Copy link

JackWH commented Feb 23, 2011

@kasperfp thanks to @mdgrech23, I'm a step closer (possibly - not sure if the new error I'm getting is caused by those changes though...).

Whilst that function wasn't in Elliot's library, we can still configure the CURL parameters in ours. Change the private function _addCurl in Elliot's library to be like this:

private function _addCurl($url, $params = array())
    {
        $ch = $this->_ch;

        // !Configure CURL - see https://github.com/elliothaughin/codeigniter-facebook/issues/5#comment_801141
        curl_setopt($this->_ch, CURLOPT_SSL_VERIFYPEER, false);

        $key = (string) $ch;
        $this->_requests[$key] = $ch;

        $response = curl_multi_add_handle($this->_mch, $ch);

        if ( $response === CURLM_OK || $response === CURLM_CALL_MULTI_PERFORM )
        {
            do {
                $mch = curl_multi_exec($this->_mch, $active);
            } while ( $mch === CURLM_CALL_MULTI_PERFORM );

            return $this->_getResponse($key);
        }
        else
        {
            return $response;
        }
    }

(The 5th and 6th lines are my changes).

This no longer returns the error I was having in Issue #4 - hence why I think I'm a step closer. The new error returned reads:

exception 'facebookException' with message '400 | Request Failed - OAuthException - An active access token must be used to query information about the current user'

Now what to do...!?!

@kasperfilstrup
Copy link
Author

If it's really that easy, can someone please tell me the point of using Elliots library?

How do you get a user's ID and/or email address in your example, mdgrech23?

@kasperfilstrup
Copy link
Author

mdgrech23, it throws the same exception as Elliots library and as JackWebbHeller is experiencing:

" Uncaught OAuthException: An active access token must be used to query information about the current user "

Thing is, I modified Facebook.php to have the following two extra options when using curl:

$opts[CURLOPT_SSL_VERIFYHOST] = 0;
$opts[CURLOPT_SSL_VERIFYPEER] = 0;

Why? Because as default (without those two settings), it threw this error:

"Fatal error: Uncaught CurlException: 60: SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed thrown in "

So I'm not sure it's Elliots library there's something wrong with. Sound like a general issue.. :-/

@JackWH
Copy link

JackWH commented Feb 25, 2011

I tried uploading my copy (using Elliot's library) to my MediaTemple webserver. Again, same issue there, so I don't think it's a local/WAMP/MAMP problem.

Thought: @mdgrech23, in your CI config, have you changed any of this configuration in your config.php file?

/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string.  The default setting of "AUTO" works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO'            Default - auto detects
| 'PATH_INFO'       Uses the PATH_INFO
| 'QUERY_STRING'    Uses the QUERY_STRING
| 'REQUEST_URI'     Uses the REQUEST_URI
| 'ORIG_PATH_INFO'  Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = "AUTO";

or...

/*
|--------------------------------------------------------------------------
| Enable Query Strings
|--------------------------------------------------------------------------
|
| By default CodeIgniter uses search-engine friendly segment based URLs:
| example.com/who/what/where/
|
| By default CodeIgniter enables access to the $_GET array.  If for some
| reason you would like to disable it, set 'allow_get_array' to FALSE.
|
| You can optionally enable standard query string based URLs:
| example.com?who=me&what=something&where=here
|
| Options are: TRUE or FALSE (boolean)
|
| The other items let you set the query string 'words' that will
| invoke your controllers and its functions:
| example.com/index.php?c=controller&m=function
|
| Please note that some of the helpers won't work as expected when
| this feature is enabled, since CodeIgniter is designed primarily to
| use segment based URLs.
|
*/
$config['allow_get_array']      = TRUE;
$config['enable_query_strings'] = FALSE;
$config['controller_trigger']   = 'c';
$config['function_trigger']     = 'm';
$config['directory_trigger']    = 'd'; // experimental not currently in use

The reason I ask is (I believe) the access token is passed back to CI via a query string, so I was wondering whether changing any of these parameters might do the trick.

Jack

@thocutt1020
Copy link

If it helps I've installed all the facebook files into a Reactor App. The error receiving is

A PHP Error was encountered

Severity: Notice

Message: facebookSession::_find_token() [facebooksession.-find-token]: The script tried to execute a method or access a property of an incomplete object. Please ensure that the class definition "facebookResponse" of the object you are trying to operate on was loaded before unserialize() gets called or provide a __autoload() function to load the class definition

Filename: libraries/facebook.php

Line Number: 414

@elliothaughin
Copy link
Owner

Ok guys, I think I know where this issue lies. It's something to do with the find_token method, but strangely, the whole thing works fine on my system and server.

That might be because I have fast_cgi or something similar.

So, I'll get this bug squashed this weekend. Promise!

@JackWH
Copy link

JackWH commented Mar 8, 2011

Awesome - thanks Elliot! Really appreciated :)

@thocutt1020
Copy link

Dude, that will be so awesome! I'm psyched to get it integrated and see what I can do with this facebook stuff. Thanks EH!

@kasperfilstrup
Copy link
Author

Much appreciated Elliot. Looking forward to a solution! :-)

@flcoder
Copy link

flcoder commented Mar 9, 2011

It works fine on my server hosted with EApps... you can find phpinfo() output at http://flcoder.com and the PLog app, which is nothing at the moment but the default ci-fb installation at http://flcoder.com/PLog/index.php/facebook_test . I'm brand new to CI so I'm not sure why http://flcoder.com/PLog/facebook_test doesn't serve anything. I must have installed CI wrong I'm guessing. Actually I realized there's no htaccess file to make the pretty URLs out-of-box, so this is actually expected behavior. The ci-fb installation instructions threw me off when it said check http://yoursite/facebook_test . I'm just new to CI.

For those having problems, has anyone tried just going with the standard Facebook library and seeing if they are getting different results... this would narrow the source of the problem down. There's no need to waste time picking through CI or Elliot's ci-fb library if it is actually something that has to do with php configuration.

@heriniaina
Copy link

flcoder> I don't think yours works either.

I went to http://flcoder.com/PLog/index.php/facebook_test

And I got

"An error occurred with PLog. Please try again later."

That's also what I got with mine

@flcoder
Copy link

flcoder commented Mar 15, 2011

I tested with both IE and FF from my work computer and it works as
intended. I tried uninstalling the PLog app and then going to
http://flcoder.com/PLog/index.php/facebook_test. Everything seems to
be working fine. So, at this point I'm wondering if it has to do with
browser settings. But what's really needed is another test subject to
go to the site and let us know their results. How many people are
getting an error with http://flcoder.com/PLog/index.php/facebook_test
and how many people successfully login and see their data retrieved.
So anyone reading, please let me know. I will also try testing from
my computer at home as well when I get off work.

@heriniaina
Copy link

Just tested with 3 computers in 3 different location (1 from France) and using 3 FB accounts

Always the same error, only in different languages. After login

Si è verificato un errore con PLog. Riprova più tardi.

An error occurred with PLog. Please try again later.

@flcoder
Copy link

flcoder commented Mar 15, 2011

Were any of them U.S. based? I can't reproduce the error.

@heriniaina
Copy link

flcoder> No. 2 from Italy, 1 from france.

@heriniaina
Copy link

flcoder> So this works for you?

http://namana.serasera.org/namana/facebook_test

@flcoder
Copy link

flcoder commented Mar 16, 2011

No... I get the same error you describe. I'm on my home computer and
the one on my server still works fine. This is daunting.

On Tue, Mar 15, 2011 at 10:36 PM, heriniaina
reply@reply.github.com
wrote:

flcoder> So this works for you?

http://namana.serasera.org/namana/facebook_test

Reply to this email directly or view it on GitHub:
#5 (comment)

@heriniaina
Copy link

I dropped using this (though I appreciate Eliots' work)

Now I'm back to the source https://github.com/facebook/php-sdk

So it's working.

Thanks to all

http://hery.serasera.org
"Tsiky dia ampy"
Tel +39 338 744 2412

On Fri, Mar 18, 2011 at 9:49 AM, mftaher
reply@reply.github.com
wrote:

Finally, I got it to work but it's not neat as eliots code but it works. The problem was assigning token to access token in _find_token function. $token is a string variable and access_token was not accessible as object reference therefor I did the hack to explode $token with '&'  and then set in session as array $token. Then you can get the access_token as $token[0]. You'll have to change the _token_string() to return $token[0].

After that you'll face the problem of $user->name. You'll have to do json_decode to get user data before you print like $user->name.

There's a problem with expire time set since its kept as string as "expires=1345". I'm waiting for eliots update before I spent any more time on this. For now I'm ok with this hack.

Reply to this email directly or view it on GitHub:
#5 (comment)

@flcoder
Copy link

flcoder commented Mar 18, 2011

Hmm... this doesn't make any sense. Why would one person from one computer be able to access the app but another person from another computer end up getting an error message. It just doesn't make sense. And the error message is REALLY explanatory: "An error occurred with APP_NAME. Please try again later" - wow, that's really pro.

See, what's really upsetting me is that I could spend a month writing an FB App and think that it's working great only to find out that half my user base can't even access the app. This is BS!

I'd really like to get down to the bottom of answering the question: Why is it that some users can access the app and some can't?

@PirateChurch
Copy link

Has anyone figured this out yet? Ive tried it on a few different servers and have the same issues listed on every one of them.

I also tried enabling fast_cgi since Eliot posted that it could be related... no joy for me on that one.

fingers crossed that you figure this our Eliot. I've tried a few different ways of integrating FB into my CI and yours looks to be the most promising if we can just get it to work.

*edit: running on a MT DV server (Cent OS) if that has an impact on anyones troubleshooting.

@PirateChurch
Copy link

came up with a really hacky fix for the initial login problem... still exploring the rest to see if anything else is broken.
in libraries/facebook.php replace line 410:
$token = $this->_get('token');

with:
$token = unserialize (serialize ($this->_get('token')));

... then login, logout etc should work fine.

Like I said, I haven't looked into the rest yet.

@PirateChurch
Copy link

Better still since we dunno if its a server specific issue:
inserted before _find_token():

private function fixToken($token){
            if(!is_object ($token) && gettype ($token) == 'object'){
                return unserialize (serialize ($token));
            } else {
                return $token;
            }
        }

and then change the first line of _find_token():

private function _find_token()
        {
            $token = $this->fixToken($this->_get('token'));
            
            if ( !empty($token) )...

alright. Ill stop commenting now.

@mftaher
Copy link

mftaher commented Mar 28, 2011

It isn't working ... same old story ... did you do anything else?

@PirateChurch
Copy link

nope. with that one change everything works now.

what error(s) are you getting with those changes in place? I'm running 2.0.1

just did a fresh download of Elliots code from here, made the change to the library and checked it again, login/logout and wall post calls work with no problems.

@mftaher
Copy link

mftaher commented Mar 29, 2011

login/logout state doesn't change ...
had FB exception at first that jackwebb described above and got it fixed with his solution, but still login/logout state doesn't change ... It's always showing logout state
I'm running CI 2.0 ...
WAMP server

@PirateChurch
Copy link

have you tried it with a clean download of this library so the only change is the one I made to libraries/facebook.php on line 410?

replace
$token = $this->_get('token');
with:
$token = unserialize (serialize ($this->_get('token')));

this is the simpler of the two and should at least return a clear error if its not working.
if there are other changes in play then I have no idea what you would need to do.

@mftaher
Copy link

mftaher commented Mar 30, 2011

yes, i did a clean install. I tried your previous hack and also this one, now i'm getting a error

Maximum function nesting level of '100' reached, aborting! in C:\wamp\www\codeigniter\swooper\libraries\facebook.php on line 410

any ideas?

@PirateChurch
Copy link

hmm. this is the error you get when just running the facebook_test controller Elliot provided? It sounds like some sort of recursion problem although Ive never encountered it before.

Ive never used WAMP but just tried out a clean CI 2.0.1 install with Elliots library on Windows 7 running XAMPP and it worked just as well as it did on my MT DV server.

do you have the XDebug extension active in your php install? check your php.ini for it.

try turning it off... that may solve the issue. If it does and you wanna satisfy a curiosity of mine, turn it back on and chenge the xdebug.max_nesting_level to something a lot higher and try running the code again.

I'd like to know how much nesting is going on that would cause an error like this.

If that doesnt solve it, the whole problem would make sense to me if you were calling a facebook library function in a controller of your own... since there could be a bad call or something causing a loop which would turn into too much / endless recursion.

Im pretty much out of ideas if you're running totally clean code up to my suggested edit and dont have xdebug active.

can you put it on a publicly accessible server so I could take a look?

sorry. thats all I got right now ;)

hopefully Elliot will come back with a real fix since he understands the code he wrote better than any of us do at this point.

@PirateChurch
Copy link

just googled a little and apparently Zend, Ioncube and XDebug can all cause this error.

changing the settings in the ini can solve it but if you do have a real recursion problem then you will prolly hit a memory issue at some point

@PirateChurch
Copy link

OK... final thought although I cant test it here... try using the === comparison operator on line 410 rather than the ==

if(!is_object ($token) && gettype ($token) === 'object'){

rather than

if(!is_object ($token) && gettype ($token) == 'object'){

lemme know if that solves it. if so its my bad not Elliots... wasn't necessarily strict enough with the object comparison. works fine in php 5.2.6 though ;)

*edit: no... I think at this point I'm over-thinking it. I doubt this is right but, like I said, I cant check it here.

@mftaher
Copy link

mftaher commented Mar 30, 2011

I'm using fresh install, nothing.

If I use as above then no error, but login/logout state doesn't change after I login to facebook.

It throws an exception in _find_token(), which occurs from add_curl() same error posted previous in the forum.

I'm running php 5.3.5

@PirateChurch
Copy link

tried your link and I see what you mean...

sorry. I'm pretty much out of ideas man.

maybe a WAMP issue? total conjecture on my part but I would try running it on a different server configuration if I were in your shoes.

@ghost
Copy link

ghost commented Mar 30, 2011

I think I have found where the problem is. I did this following way:

  1. Since even after authentication, it is showing Login link,
    $this->facebook->logged_in() is false.
  2. I further went back, and found that get() function was not actually getting the session variables from CodeIgniter's session, possibly because these variable are not actually being set. I verified this by printing session variable. ( no '_facebook_xxx' kind of session variables were set). So the PROBLEM IS SESSION VARIABLES ARE NOT BEING SET.
  3. I went further and found some strange things in the definition of _getResponse($key=NULL) function. I added few lines to log messages following ways, and the strange thing I noted is the line 24 is repeated several hundreds of time, which means do...while loop is being executed several hundreds of times. I am not sure if it is common with curl_multi_exec function. Here is the data from my log file:

24 INFO - 2011-03-30 23:52:45 --> #### before curl_multi_exec
25 INFO - 2011-03-30 23:52:45 --> #### before curl_multi_exec
... [this line is repeated several hundreds of time]
1682 INFO - 2011-03-30 23:52:45 --> #### before curl_multi_exec
1683 INFO - 2011-03-30 23:52:45 --> #### before curl_multi_exec
1684 INFO - 2011-03-31 00:43:59 --> #### running = 1 and $running_curl = 0
1685 INFO - 2011-03-30 23:52:45 --> #### before _setResponse
1686 INFO - 2011-03-30 23:52:45 --> #### before new facebookResponse()
1687 INFO - 2011-03-30 23:52:45 --> #### Inside __resp->code !== 200
1688 INFO - 2011-03-30 23:52:45 --> #### error before __resp->data->error->type 0 | Request Failed

And here is the original function I added lines to :

private function _getResponse($key = NULL)
{
if ( $key == NULL ) return FALSE;

if ( isset($this->_responses[$key]) )
{
    return $this->_responses[$key];
}

$running = NULL;

do
{   
    log_message('info', '#### before curl_multi_exec');
    $response = curl_multi_exec($this->_mch, $running_curl);

    if ( $running !== NULL && $running_curl != $running )
    {
        log_message('info', '#### running = '.$running . ' and $running_curl = '.$running_curl);
        log_message('info', '#### before _setResponse');
        $this->_setResponse($key);

        if ( isset($this->_responses[$key]) )
        {
            log_message('info', '#### before new facebookResponse()');
            $response = new facebookResponse( (object) $this->_responses[$key] );

            if ( $response->__resp->code !== 200 )
            {
                log_message('info', '#### Inside __resp->code !== 200');
                $error = $response->__resp->code.' | Request Failed';
                log_message('info', '#### error before __resp->data->error->type '.$error);

                if ( isset($response->__resp->data->error->type) )
                {
                    $error .= ' - '.$response->__resp->data->error->type.' - '.$response->__resp->data->error->message;
                    log_message('info', '#### final error'.$error);
                }

                throw new facebookException($error);
            }

            return $response;
        }
    }

    $running = $running_curl;

} while ( $running_curl > 0);

}

I am using XAMPPLITE on Windows Vista with cURL extension on. In my opinion, the problem is not with XAMPP or WAMP, but problem is with the method by which CodeIgniter is reading/saving/using the data sent by/from Facebook.

Let me also tell you that, I have also used Official Facebook PHP SDK in my CodeIgniter 2.0 project, and it worked very well. There's a function getSignedRequest() which reads all the data by/from Facebook and return as array. May be the solution to our problem lies somewhere here.

@mftaher
Copy link

mftaher commented Mar 30, 2011

Can someone explain why does it have to use curl_multi_exec? and not curl_exec?

@Xen23
Copy link

Xen23 commented Apr 1, 2011

Has anyone had any more luck with working this out? I'd really like to use this library in my projects but am just getting the 'Login' link irregardless of whether I'm logged into Facebook or not..?

@mftaher
Copy link

mftaher commented Apr 1, 2011

try piratechurch's solution ... it should work .. although I couldn't get it worked i completely agree with tj2point0 on the problem, it works without the _addCurl() .. remember you'll need 'codeigniter reactor' ...

@ghost
Copy link

ghost commented Apr 1, 2011

I found two solutions by persons who already tried elliot's library.

  1. key2market[dot]com http://goo.gl/SUzw5
  2. dannyherran[dot]com http://goo.gl/MgMR7

I tried all of them, and all of them worked for me, except elliot's library with setting session problem. Above two solutions are very easy.

After studying above two solutions, I found solution to another problem, about SSL issue. Facebook PHP SDK comes with a file 'fb_ca_chain_bundle.crt' which is required for authentication. Someone somewhere suggested to make CURLOPT_SSL_VERIFYPEER option to false. I guess, doing so will cause security problems. My solution is to keep Facebook php sdk file AND 'fb_ca_chain_bundle.crt' in CodeIgnier Application's Third Party folder. Because while authenticating, facebook will look for this file exactly where we kept facebook.php, and CI won't allow access to this file from 'library' folder...

And finally, I experienced one problem with almost all the CodeIgniter Facebook methods, is just after I click to authenticate it goes into infinite loop of reloading the page. When I tracked down the problem, I found it is with the function in the script. Anyone worked on this? Here's the code:

FB.Event.subscribe('auth.login', function() {
window.location.reload();
});
};

@arisanguinetti
Copy link

Hi All,

I have this workarround for the findToken error.

First of all, you should disable the autoload of the session library for your app.

Then you should divide your app in at least 2 controllers, one for logging with Facebook and saving in a database the user information, and send to the other (with the CI Session library loaded) ia URL the ID od the user in database.

BTW, If you would like to use the Facebook library and the Twitter library togheter, you should load Facebook first.

Hope this help!

@mastacheata
Copy link

@tj2point0:
Do you call $this->facebook->login() in the same controller-function or view as the FB.event.subscribe JS function?
If you don't then this should not be a problem. Even more the opposite is the case. If you don't reload the page after authentication the JavaScript / FBXML / FB Social Plugins won't work as expected.

@arisanguinetti:
You might want to have a look at my pull request.
I implemented a function similar to the one in Elliot's Twitter library to store and load the token to/from outside the session/facebook library.
And thanks for the hint with loading twitter and facebook library in that order, seems like an issue with the session handling if a session already exists. Though I don't know where exactly this problem is based.
@mftaher: curl_multi_exec allows to execute multiple curl handles at once on multi-thread systems in opposite to curl_exec which only allows to process one request at a time.

@CitizenBeta
Copy link

I'm still having an issue with always seeing 'login'. Is Elliot still supporting this package?

@mastacheata
Copy link

@golevel:
It's almost 3 months since elliot did anything here, so I guess he does not actively provide support of any kind.
I tried to contact him on twitter a few weeks ago and still did not receive any answer.

@nicholasruunu
Copy link

I talked to him on Twitter and he told me that he was very busy with some new job opportunity and didn't have time to contribute to the Facebook Library at the time. Maybe someone is interested enough to branch out on this project?

@CitizenBeta
Copy link

No need, really. I just followed this guide to the letter and it works perfectly:

http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/

@creativenode
Copy link

Second what golevel said, http://www.dannyherran.com/2011/02/facebook-php-sdk-and-codeigniter-for-basic-user-authentication/ works a treat up and running in 10 minutes :-) Happy Days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests