Skip to content
This repository has been archived by the owner on Jan 13, 2022. It is now read-only.

Getting Error Undefined array key #1246

Open
yhchen0 opened this issue Jul 15, 2021 · 3 comments
Open

Getting Error Undefined array key #1246

yhchen0 opened this issue Jul 15, 2021 · 3 comments

Comments

@yhchen0
Copy link

yhchen0 commented Jul 15, 2021

I want get user info, so I try use:

$targetUrl = "https://graph.facebook.com/v11.0/oauth/access_token";
$getAccessTokenRes = Http::get($targetUrl, [
    'client_id' => $client_id,
    'client_secret' => $client_secret,
    'redirect_uri' => $redirectURL,
    'code' => $code
]);
$accessToken = json_decode($getAccessTokenRes->body())->access_token;
$accessUserInfo = $fb->get('/me', $accessToken); //Get Error

Error message is: ErrorException Undefined array key 1
After tracing, I found that the error came from
vendor/facebook/graph-sdk/src/Facebook/Http/GraphRawResponse.php:109

public function setHttpResponseCodeFromHeader($rawResponseHeader)
{
    preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $rawResponseHeader, $match); // $rawResponseHeader = 'HTTP/2 200'
    $this->httpResponseCode = (int)$match[1];
}

I try to use var_dump print $rawResponseHeader value, the content is HTTP/2 200
I think it is because the content does not match the pattern of preg_match, which causes the error.

I am very confused, because I tried to create two Facebook applications, the first time was successful, but the second application encountered this problem.

@ldanielduarte
Copy link

setHttpResponseCodeFromHeader it is very poorly designed! It is not compatible with HTTP/2
Does anyone knows a fork with this fixed?

@NouvelleTechno
Copy link

Hello,

This could be fixed by changing line 107 to

preg_match('/HTTP\/\d(?:\.\d)?\s+(\d+)\s+/',$rawResponseHeader, $match);

Would need an official fix as editing the file is not recommended

@lairen213
Copy link

Hello,

This could be fixed by changing line 107 to

preg_match('/HTTP\/\d(?:\.\d)?\s+(\d+)\s+/',$rawResponseHeader, $match);

Would need an official fix as editing the file is not recommended

thx! That's help me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants