15

I'm trying to develop a sample facebook php login example following the example here

I've hosted my app here, but I'm getting the error message in the question whenever I try to access the link. Here's the code segment that throws the error

try {
  $e = new FacebookApiException(array(// LINE 887
             'error_code' => curl_errno($ch),
             'error' => array(
             'message' => curl_error($ch),
             'type' => 'CurlException',
        ),
  ));
  curl_close($ch);
}

// edit suggested by Kneel-before ZOD
catch(FacebookApiException $e) {
  $result = $e->getResult();
  echo 'Got an : ', $e->getType(),' while posting';
  echo(json_encode($result));
}

catch(Exception $e){
  echo 'Caught exception: ',  $e->getMessage(), "\n";
}

Im quite sure Ive setup the APP ID and secret correctly in index.php.

Here's a screenshot of my app setup on facebookApp setup

Any help would be appreciated. Thanks!

BillyBigPotatoes
  • 1,330
  • 11
  • 23
seeker
  • 6,841
  • 24
  • 64
  • 100
  • Have you checked the `host`'s URL? – Kneel-Before-ZOD Sep 18 '13 at 18:07
  • @Kneel-Before-ZOD. I dont get you? AFAI see, the `host` url is http://cse591.host56.com. Am I missing something here? – seeker Sep 18 '13 at 18:23
  • Does the **host** in the FB API match **http:// cse591.host56.com/** ? – Kneel-Before-ZOD Sep 18 '13 at 18:46
  • Never mind; the image answered the question. check the location of the error and paste the content. – Kneel-Before-ZOD Sep 18 '13 at 18:56
  • @Kneel-Before-ZOD: Ive posted the relevant code lines in the question . Please take a look – seeker Sep 18 '13 at 19:43
  • Are you certain you are executing the FB API correctly? [The official link](https://developers.facebook.com/docs/reference/php/#exception_object) seems to disagree with what you are doing. – Kneel-Before-ZOD Sep 18 '13 at 20:46
  • Doesnt help, I tried your suggestion .(Code in post) But I still get the same error. – seeker Sep 18 '13 at 22:02
  • maybe I wasn't very clear. The FB class to access your app should be the **Facebook Object** class, not the **facebookApiException**; the code you posted showed that you are trying to access an Exception class and not an API class. Use [this link](https://developers.facebook.com/docs/php/gettingstarted/) to get you started. – Kneel-Before-ZOD Sep 18 '13 at 23:11
  • Hi @Kneel-Before-ZOD , I used the link and setup a separate project from scratch . And I get the same error as before. Plus, I dont really understand point, as the error is being thrown in the _library_ code and not mine. Please correct me if I'm wrong. – seeker Sep 20 '13 at 02:36
  • First step first is your curl is on and working http://www.vbulletin.com/forum/forum/vbulletin-legacy-versions-products/legacy-vbulletin-versions/vbulletin-3-7-questions-problems-and-troubleshooting/375649-warning-curl-setopt-%5Bfunction-curl-setopt%5D-invalid-curl-configuration-option look this link – shafiq.rst Sep 28 '13 at 07:21
  • Do you mean to ask whether the server has Curl support? AFAIK it does http://cse591.host56.com/info.php – seeker Sep 28 '13 at 08:12

11 Answers11

1

You may need to give curl a certificate file for Facebook which you do like this:

Download the certificate files from https://github.com/facebookarchive/facebook-php-sdk/blob/master/src/fb_ca_chain_bundle.crt

and add this before attempting any Facebook calls

facebook::$CURL_OPTS[CURLOPT_CAINFO] = 'path/to/fb_ca_chain_bundle.crt';

You could also try

facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYPEER] = false;
facebook::$CURL_OPTS[CURLOPT_SSL_VERIFYHOST] = 2;
Hugh Wormington
  • 305
  • 1
  • 2
  • 10
0

why are you creating the exception on the try block?

my current working login function goes something like this:

public function login()
{               
    $this->load->library('facebook/facebook',$config);
    $uid = $this->facebook->getUser();

    if ($uid) 
    {           
      try 
      {             
        $user_profile = $this->facebook->api('/' . $uid);  

        //then redirect to whatever you need..
      } 
      catch (FacebookApiException $e) 
      { error_log($e);
        $uid = null;
        $this->facebook->destroySession();
      }
    }
    else 
    {
        $params = array(
            'canvas'    => 1,
            'fbconnect' => 0,
            'scope' => 'email',
        );
        echo "<script>top.location.href='" . $this->facebook->getLoginUrl($params)."'</script>";            
        exit();
    }
}
italo.portinho
  • 121
  • 1
  • 5
  • the error is being thrown from the library files and not my client code. My client code is similar to your file above. – seeker Sep 23 '13 at 19:43
  • hmm isee. is it on base_facebook.php which function? i dont find those lines on my file. make sure you are using the latest version. – italo.portinho Sep 23 '13 at 19:49
  • Yes. And I just used the latest version from facebook's php -sdk page – seeker Sep 24 '13 at 02:27
0

I had the same problem like you.

I add this option before curl_exec() in base_facebook.php

curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  • that gives me `Parse error: syntax error, unexpected T_IF in /home/a8815401/facebook/src/base_facebook.php on line 20` . And this is the code on line 20 `curl_exec() if (!function_exists('curl_init')) { //line20 throw new Exception('Facebook needs the CURL PHP extension.'); }` – seeker Sep 26 '13 at 02:35
  • I added this option to line 962. [base_facebook.php](https://github.com/facebook/facebook-php-sdk/blob/master/src/base_facebook.php "facebook-php-sdk/src/base_facebook.php at master · facebook/facebook-php-sdk") – Tomotsugu Kaneko Sep 27 '13 at 02:48
  • I removed it previous line and added it on line 962. I get a warning and an error now. `Warning: curl_setopt() [function.curl-setopt]: Invalid curl configuration option in /home/a8815401/facebook/src/base_facebook.php on line 962` `Fatal error: Uncaught CurlException: 7: couldn't connect to host thrown in /home/a8815401/facebook/src/base_facebook.php on line 994`. Any thoughts? – seeker Sep 28 '13 at 01:44
  • http://www.000webhost.com/forum/customer-assistance/35188-facebook-connect-fatal-error-uncaught-curlexception-7-a.html – Dilip Raj Baral Oct 07 '13 at 18:06
0

If you are using free hosting , I think it may not going to work, mostly because they usually disabled outgoing connection. I also have faced this problem with the code that worked smoothly on paid hosting(or outgoing connection enabled).

Ashutosh Bajpay
  • 23
  • 1
  • 10
0

You are creating an exception in try ... catch block. You don't need to do such things. try-catch block designed to handle code segments which can throw an exception in your applications. You need to put inside this block code segments that can throw an exception. In your case it may be a cURL request to the Facebook API.

user3486769
  • 61
  • 1
  • 3
0

It has nothing to do with your code. Curl simply can't connect to the facebook graph API. This could either be because your host is blocking outgoing connections to other hosts or facebook is blocking your host.

If you have ssh access you could try to reach http://graph.facebook.com and/ or check your php logs. Otherwise you should ask your host.

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
fabs
  • 77
  • 1
  • 1
  • 13
0

The link is https you may have to supply the certificate info or curl will usually throw an error if you don't have access to the certificate then adding

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

will allow access to any certificate.

RobNHood
  • 119
  • 1
  • 2
  • 11
0

Set Proxy To Connect Facebook.com

## Find Code In base_facebook.php ##

public static $CURL_OPTS = array(
        CURLOPT_CONNECTTIMEOUT => 10,
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_TIMEOUT        => 60,
        CURLOPT_USERAGENT      => 'facebook-php-3.2',
      );

And Add option

  public static $CURL_OPTS = array(
    CURLOPT_CONNECTTIMEOUT => 10,
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_TIMEOUT        => 60,
    CURLOPT_USERAGENT      => 'facebook-php-3.2',
    CURLOPT_PROXY      => '199.200.120.140:8089',
  );
0

As suggested by Ashutosh Bajpay, it's likely that your web server is unable to connect based on the error message. If you're using a shared hosting provider, or have SELinux enabled, it's highly plausible that your code will not be able to initiate a new connection out.

You can write a quick and dirty script to test this theory:

$page = file_get_contents('http://google.com');
(!empty($page)) ? var_dump($page) : print_r(error_get_last());

If the script can connect, you'll get a dump of the page, otherwise you should see an error with it attempting to get to the host.

If you do have control of the box, and it happens to be running SELinux there are some useful tips here.

Paweł Tomkiel
  • 1,974
  • 2
  • 21
  • 39
DalML
  • 1
0

Check your php.ini allows curl function.

For ubantu try to this code in your terminal

sudo apt-get install php5-curl

After it restart your apache server using

sudo service apache2 restart

Ferrmolina
  • 2,737
  • 2
  • 30
  • 46
Mohit maru
  • 817
  • 8
  • 15
0

You are catching two exception types, neither is the exception that is "thrown". Try catching the exception that is thrown and within that exception block you'll be able to further debug your problem (such as showing the variables in play during the exception ...) then you can build a simple page to test each piece of the puzzle until you fix it.

TheSatinKnight
  • 696
  • 7
  • 16