0

I went to the following URL: http://developers.facebook.com/docs/reference/php/facebook-api/ I copied the first example to my server my replacing the appID and secret for my own app. When I visit the page it says "Please login" as seen in the code, when I press that button the app reloads and it keeps saying the same thing. Im logged into Facebook already but even when I press login nothing happens.

I was wondering if anyone knew what the issue is? I have the SDK files in a folder where index.php is called src, so I have edited the path to 'src/facebook.php'?


EDIT - I am getting the following error (replaced real file path). I have just found out it could be something to do with a proxy?

Error found:

FacebookApiException Object
(
    [result:protected] => Array
        (
            [error_code] => 7
            [error] => Array
                (
                    [message] => couldn't connect to host
                    [type] => CurlException
                )

        )

    [message:protected] => couldn't connect to host
    [string:Exception:private] => 
    [code:protected] => 7
    [file:protected] => filepath/src/base_facebook.php
    [line:protected] => 977
    [trace:Exception:private] => Array
6
  • 1
    And you get no errors in your console or otherwise? Commented Feb 6, 2013 at 23:17
  • No errors anywhere, nothing in Dreamweaver and the file path is definitely correct. Commented Feb 6, 2013 at 23:23
  • What server package are you using? Commented Feb 6, 2013 at 23:27
  • Its hosted on my university server so im assuming everything is correct and working, could file permissions be causing the problem? Commented Feb 6, 2013 at 23:29
  • Unsure at this point; could you please list your permissions, but first open the page in chrome/firefox and check the inspector/firebug for any errors? Commented Feb 6, 2013 at 23:33

2 Answers 2

1

I think this is the problem:

catch(FacebookApiException $e) {
    // If the user is logged out, you can have a 
    // user ID even though the access token is invalid.
    // In this case, we'll get an exception, so we'll
    // just ask the user to login again here.
    $login_url = $facebook->getLoginUrl(); 
    echo 'Please <a href="' . $login_url . '">login.</a>';
    error_log($e->getType());
    error_log($e->getMessage());
  }  

Facebook demos do this, and its really annoying. It assumes that any exception you get is because of an expired user token, whereas it is probably down to a typo or other error.

So what I would do is change this to simply display the contents of $e.

 catch(FacebookApiException $e) {
    echo 'Error found:';
    echo '<br />Type: '.$e->getType();
    echo '<br />Message: '.$e->getMessage();
    exit;  
 }  

Then at least you can see easily what the error is. Once you have it working, by all means change it back.

You can get even more information if you use the following:

 catch(FacebookApiException $e) {
    echo 'Error found:';
    echo '<br /><pre>';
    print_r($e);
    echo '</pre>';
    exit;  
 }  

This will produce pages of very similar data. I normally find what I need right near the top though.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a lot, just tried it and got the following error: Error found: Type: CurlException Message: couldn't connect to host Although ive no idea how to go about correcting it!?
PHP info says curl support enabled.. :/
I've edited my answer to show you a way of getting more error info. The more info you can provide the more help you will get. Also, test curl is working on your server by running a bit of sample php code, like this one: pastebin.com/fLcuGGPZ If that works then you know you can rule curl out as the cause. The problem may also be that your site doesn't have a valid SSL certificate. This could be generating the curl error.
Thanks a lot, ive edited my original post with the error received from the last snippet you posted.
0

I would use Fiddler to check what bits are going over the wire (or that bits are going over the wire at all).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.