Facebook PHP API throwing exception while login
up vote
0
down vote
favorite
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.ds+(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();
}
php facebook facebook-graph-api
add a comment |
up vote
0
down vote
favorite
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.ds+(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();
}
php facebook facebook-graph-api
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
1
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/…
– B. Fleming
Nov 15 at 21:25
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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.ds+(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();
}
php facebook facebook-graph-api
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.ds+(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();
}
php facebook facebook-graph-api
php facebook facebook-graph-api
edited Nov 15 at 20:58
asked Nov 15 at 20:07
Prappo Prince
326312
326312
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
1
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/…
– B. Fleming
Nov 15 at 21:25
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32
add a comment |
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
1
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/…
– B. Fleming
Nov 15 at 21:25
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
1
1
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 method getHttpStatusCode()
mentioned here?: developers.facebook.com/docs/php/FacebookResponse/…– B. Fleming
Nov 15 at 21:25
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 method getHttpStatusCode()
mentioned here?: developers.facebook.com/docs/php/FacebookResponse/…– B. Fleming
Nov 15 at 21:25
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
I think you're using an outdated version of the Facebook SDK (php-sdk-v4), you should be using version 5.
https://github.com/facebook/php-graph-sdk
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
add a comment |
up vote
0
down vote
This appears to be a known issue in the PHP graph SDK. This issue had a fix applied only two days ago, as can be seen in the GitHub issues on its repo. The last release, on the other hand, was in early July, so this fix is currently unavailable in the most current release version of the SDK.
You have a few options available to you:
- You could try downgrading your version of curl used by PHP.
- If you're willing to run a potentially unstable version of the SDK, you could look into updating to the master branch rather than a release version.
- You could apply a hotfix matching the fix that was committed to the repo.
These are given in order of most preferred to least preferred, with stability and reliability being the primary concern.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327170%2ffacebook-php-api-throwing-exception-while-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think you're using an outdated version of the Facebook SDK (php-sdk-v4), you should be using version 5.
https://github.com/facebook/php-graph-sdk
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
add a comment |
up vote
0
down vote
I think you're using an outdated version of the Facebook SDK (php-sdk-v4), you should be using version 5.
https://github.com/facebook/php-graph-sdk
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
add a comment |
up vote
0
down vote
up vote
0
down vote
I think you're using an outdated version of the Facebook SDK (php-sdk-v4), you should be using version 5.
https://github.com/facebook/php-graph-sdk
I think you're using an outdated version of the Facebook SDK (php-sdk-v4), you should be using version 5.
https://github.com/facebook/php-graph-sdk
answered Nov 16 at 2:33
Andrea Olivato
209211
209211
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
add a comment |
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
I'm using the latest version of PHP graph SDK. it's 5.6
– Prappo Prince
Nov 16 at 6:26
add a comment |
up vote
0
down vote
This appears to be a known issue in the PHP graph SDK. This issue had a fix applied only two days ago, as can be seen in the GitHub issues on its repo. The last release, on the other hand, was in early July, so this fix is currently unavailable in the most current release version of the SDK.
You have a few options available to you:
- You could try downgrading your version of curl used by PHP.
- If you're willing to run a potentially unstable version of the SDK, you could look into updating to the master branch rather than a release version.
- You could apply a hotfix matching the fix that was committed to the repo.
These are given in order of most preferred to least preferred, with stability and reliability being the primary concern.
add a comment |
up vote
0
down vote
This appears to be a known issue in the PHP graph SDK. This issue had a fix applied only two days ago, as can be seen in the GitHub issues on its repo. The last release, on the other hand, was in early July, so this fix is currently unavailable in the most current release version of the SDK.
You have a few options available to you:
- You could try downgrading your version of curl used by PHP.
- If you're willing to run a potentially unstable version of the SDK, you could look into updating to the master branch rather than a release version.
- You could apply a hotfix matching the fix that was committed to the repo.
These are given in order of most preferred to least preferred, with stability and reliability being the primary concern.
add a comment |
up vote
0
down vote
up vote
0
down vote
This appears to be a known issue in the PHP graph SDK. This issue had a fix applied only two days ago, as can be seen in the GitHub issues on its repo. The last release, on the other hand, was in early July, so this fix is currently unavailable in the most current release version of the SDK.
You have a few options available to you:
- You could try downgrading your version of curl used by PHP.
- If you're willing to run a potentially unstable version of the SDK, you could look into updating to the master branch rather than a release version.
- You could apply a hotfix matching the fix that was committed to the repo.
These are given in order of most preferred to least preferred, with stability and reliability being the primary concern.
This appears to be a known issue in the PHP graph SDK. This issue had a fix applied only two days ago, as can be seen in the GitHub issues on its repo. The last release, on the other hand, was in early July, so this fix is currently unavailable in the most current release version of the SDK.
You have a few options available to you:
- You could try downgrading your version of curl used by PHP.
- If you're willing to run a potentially unstable version of the SDK, you could look into updating to the master branch rather than a release version.
- You could apply a hotfix matching the fix that was committed to the repo.
These are given in order of most preferred to least preferred, with stability and reliability being the primary concern.
answered Nov 16 at 19:47
B. Fleming
2,4071515
2,4071515
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53327170%2ffacebook-php-api-throwing-exception-while-login%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please show us the actual error you're encountering. We can't help you if we don't even know what the error is. For all we know, you could have forgotten to make some important changes in the Facebook developer console after receiving a warning. It could even be a simple matter of not having the correct domain name. It could be just about anything.
– B. Fleming
Nov 15 at 20:48
The error message is "Undefined offset: 1"
– Prappo Prince
Nov 15 at 20:59
1
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/…– B. Fleming
Nov 15 at 21:25
@B.Fleming: “It's very likely that they've changed the format of their header since you first wrote this code” - this part of the SDK itself; and I somehow doubt Facebook has changed the format of the HTTP status code line by themselves ;-) They probably did not write “defensive” code at this point, assuming that there must always be an HTTP status code with every API response. Things have probably failed in some way with the HTTP request itself for that not to be the case.
– misorude
Nov 16 at 8:07
@misorude You're right, I misread the code the first time through. After reviewing, it's possible that the issue could be related to this: github.com/facebook/php-graph-sdk/issues/1076
– B. Fleming
Nov 16 at 19:32