thrash
thrash

Reputation: 187

PHP Facebook - API

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

Upvotes: 0

Views: 1214

Answers (2)

Relaxing In Cyprus
Relaxing In Cyprus

Reputation: 2016

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.

Upvotes: 1

Mark Leighton Fisher
Mark Leighton Fisher

Reputation: 5703

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

Upvotes: 0

Related Questions