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();

}









share|improve this question
























  • 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 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












  • @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















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();

}









share|improve this question
























  • 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 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












  • @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













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();

}









share|improve this question















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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 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












  • @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










  • 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 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












  • @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












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






share|improve this answer





















  • I'm using the latest version of PHP graph SDK. it's 5.6
    – Prappo Prince
    Nov 16 at 6:26


















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:




  1. You could try downgrading your version of curl used by PHP.

  2. 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.

  3. 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.






share|improve this answer





















    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
    });


    }
    });














    draft saved

    draft discarded


















    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






    share|improve this answer





















    • I'm using the latest version of PHP graph SDK. it's 5.6
      – Prappo Prince
      Nov 16 at 6:26















    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






    share|improve this answer





















    • I'm using the latest version of PHP graph SDK. it's 5.6
      – Prappo Prince
      Nov 16 at 6:26













    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






    share|improve this answer












    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







    share|improve this answer












    share|improve this answer



    share|improve this answer










    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


















    • 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












    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:




    1. You could try downgrading your version of curl used by PHP.

    2. 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.

    3. 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.






    share|improve this answer

























      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:




      1. You could try downgrading your version of curl used by PHP.

      2. 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.

      3. 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.






      share|improve this answer























        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:




        1. You could try downgrading your version of curl used by PHP.

        2. 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.

        3. 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.






        share|improve this answer












        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:




        1. You could try downgrading your version of curl used by PHP.

        2. 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.

        3. 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.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 at 19:47









        B. Fleming

        2,4071515




        2,4071515






























            draft saved

            draft discarded




















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

            ComboBox Display Member on multiple fields

            Is it possible to collect Nectar points via Trainline?