I tried to log in with Facebook Graph API and get user info. The code I used to get user info worked before but today I tried login with facebook but Facebook API throwing this error.
Undefined offset: 1 /home/****/vendor/facebook/php-sdk-v4/src/Facebook/Http/GraphRawResponse.php on line 108
The line is in this function:
public function
setHttpResponseCodeFromHeader($rawResponseHeader)
{
preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match);
$this->httpResponseCode = (int)$match[1]; // <---- HERE
}
My Code :
$fb = new Facebook([
'app_id' => Data::get('fbAppId'),
'app_secret' => Data::get('fbAppSec'),
'default_graph_version' => 'v2.5',
]);
$helper = $fb->getRedirectLoginHelper();
$_SESSION['FBRLH_state'] = $_GET['state'];
try {
$accessToken = $helper->getAccessToken();
$_SESSION['token'] = $accessToken;
DB::table('settings')->where('userId', Auth::user()->id)->update(['fbAppToken' => $accessToken]); // save user access token to database
$this->saveFbPages(); // save facebook pages and token
$this->saveFbGroups(); // save facebook groups to database
} catch (FacebookResponseException $e) {
// When Graph returns an error
return '[a] Graph returned an error: ' . $e->getMessage();
} catch (FacebookSDKException $e) {
// When validation fails or other local issues
return '[a] Facebook SDK returned an error: ' . $e->getMessage();
}
preg_match
must be failing to parse the header for the value you're looking for. It's very likely that they've changed the format of their header since you first wrote this code. It looks to me like you're using the SDK, so why not use the appropriate SDK methodgetHttpStatusCode()
mentioned here?: developers.facebook.com/docs/php/FacebookResponse/…