Hi everyone, I have been trying to code a facebook application using the API.
Within this, I am required to include the base_facebook.php file.

But I keep gertting an error
Fatal error: Uncaught OAuthException: An active access token must be used to query information about the current user. thrown in base_facebook.php on line 1033

I have been doinf some digging around and a number of websites say there should be additional CURL information sent when hosting with godaddy shared hosting as godaddy use a proxy server.

Here is the code from the websites.

...assuming that $ch is the curl handle.

A full example...


<?php
$url = "http://www.google.com/";

$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
curl_setopt ($ch, CURLOPT_PROXY,"");
curl_setopt ($ch, CURLOPT_TIMEOUT, 120);
$response = curl_exec ($ch);
if(is_int($response)) {
    die("Errors: " . curl_errno($ch) . " : " . curl_error($ch));
}
curl_close ($ch);

print "Remote Site : $url<br /><hr />$response";
?>

Here is the curl configuration in the base_facebook.php

    curl_setopt_array($ch, $opts);
    $result = curl_exec($ch);

    if (curl_errno($ch) == 60) { // CURLE_SSL_CACERT
      self::errorLog('Invalid or no certificate authority found, '.
                     'using bundled information');
      curl_setopt($ch, CURLOPT_CAINFO,
                  dirname(__FILE__) . '/fb_ca_chain_bundle.crt');
      $result = curl_exec($ch);
    }

    if ($result === false) {
      $e = new FacebookApiException(array(
        'error_code' => curl_errno($ch),
        'error' => array(
        'message' => curl_error($ch),
        'type' => 'CurlException',
        ),
      ));
      curl_close($ch);
      throw $e;
    }
    curl_close($ch);
    return $result;
  }

What I dont no is how to add the additional curl configuration to base_facebook.php file

Cheers

Dani AI

Generated

The exception you are seeing is coming from Facebook, not cURL. It means your code is calling Graph (usually /me) without a valid access token. Before worrying about GoDaddy’s proxy, verify the OAuth flow is working end-to-end: start a session, send the user through the login dialog, and only call the API after you actually have a token. A quick guard looks like this:

session_start();

$user = $facebook->getUser();  // returns 0 if no active session/token
if (!$user) {
  header('Location: '.$facebook->getLoginUrl(array('scope' => 'email')));
  exit;
}

try {
  $me = $facebook->api('/me');
} catch (FacebookApiException $e) {
  error_log($e->getMessage());
  // token might be missing/expired; restart login
  header('Location: '.$facebook->getLoginUrl(array('scope' => 'email')));
  exit;
}

If your host really requires an outbound proxy, is on the right track about adding cURL options where the SDK builds the request. One safe tweak when tunneling HTTPS through an HTTP proxy is to enable HTTP proxy tunneling and keep strict SSL checks. You can merge these just before the SDK calls curl_setopt_array($ch, $opts);:

$opts += array(
  CURLOPT_HTTPPROXYTUNNEL => true,  // required for HTTPS over HTTP proxy
  CURLOPT_SSL_VERIFYHOST  => 2,
  CURLOPT_SSL_VERIFYPEER  => true
);
// optionally, keep the SDK's CA bundle handling for CURLE_SSL_CACERT

Quick checklist that commonly fixes this on shared hosting:

  • Call session_start() before touching the SDK (tokens are persisted in the session).
  • Use HTTPS Graph endpoints everywhere.
  • Ensure the server clock is correct; skewed time makes tokens look invalid.
  • Log the current token during debugging: error_log($facebook->getAccessToken());
  • If you add proxy settings for production, gate them behind an env var so local/dev does not break.

In short: get a real token first; only then add proxy options if your host actually requires them.

Recommended Answers

All 2 Replies

Hi,

Is this the you are currently using?

if so, then additional cURL configuration can be added like this

 public static $CURL_OPTS = array(
CURLOPT_CONNECTTIMEOUT => 10,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_TIMEOUT => 60,
## lets add proxy type 
CURLOPT_PROXYTYPE => CURLPROXY_HTTP;
## lets add the proxy ip
CURLOPT_PROXY => '';
CURLOPT_USERAGENT => 'facebook-php-3.1',

If NOT, look for function curl_setopt_array in your base_facebook.php. You should be able to see how the options were defined. Better yet, just post the code here, and we will try to help you out.

  function curl_setopt_array ($ch, $opts){

  }

CORRECTIONS!

Do it like this

 ## lets add proxy type
 CURLOPT_PROXYTYPE => CURLPROXY_HTTP,
 ## lets add the proxy ip
 CURLOPT_PROXY => '',

Use comma intead, because it is an array..... I completely missed it BIG time... :). I think I am just running out of coffee..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.