수명이 긴 토큰을 얻는 동안 신뢰할 수 없는 결과 (Unreliable results while obtaining long-lived token)


문제 설명

수명이 긴 토큰을 얻는 동안 신뢰할 수 없는 결과 (Unreliable results while obtaining long‑lived token)

여기에서 액세스 토큰에 대한 FB 지침을 따르고 있습니다. https:// developer.facebook.com/docs/facebook‑login/access‑tokens

그들은 내가 한 Javascript SDK를 사용하여 클라이언트로부터 단기 토큰을 얻으라고 말합니다. 테스트하는 동안 매번 문제 없이 유효한 단기 토큰을 얻습니다.

그런 다음 서버에서 다음과 같은 구조의 URL에 대해 cURL 요청을 만듭니다.

https://graph.facebook.com/v4.0/oauth/access_token?grant_type=fb_exchange_token&fb_exchange_token=[short‑lived‑token‑here]&client_id=[client‑ID‑here]&client_secret=[client‑secret‑here]

이것은 작동합니다. 시간의 약 10% ‑ 30%이고 다음과 같은 성공적인 응답을 얻습니다.

{"access_token":"[LONG‑TERM‑TOKEN‑HERE]","token_type":"bearer"}

그러나 시간의 70% ‑ 90%에서 다음과 같은 오류가 수신됩니다.

OpenSSL SSL_connect: SSL_ERROR_SYSCALL in connection to graph.facebook.com:443 

작동할 때와 작동하지 않을 때 완전히 무작위입니다. 내 cURL 코드는 다음과 같습니다.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_ENCODING, 'gzip, deflate');

$headers = array();
$headers[] = 'Authority: graph.facebook.com';
$headers[] = 'Pragma: no‑cache';
$headers[] = 'Cache‑Control: no‑cache';
$headers[] = 'Upgrade‑Insecure‑Requests: 1';
$headers[] = 'User‑Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36';
$headers[] = 'Sec‑Fetch‑User: ?1';
$headers[] = 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed‑exchange;v=b3;q=0.9';
$headers[] = 'Sec‑Fetch‑Site: none';
$headers[] = 'Sec‑Fetch‑Mode: navigate';
$headers[] = 'Accept‑Encoding: gzip, deflate, br';
$headers[] = 'Accept‑Language: en‑US,en;q=0.9';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
   echo 'Error:' . curl_error($ch);
}
curl_close($ch);

URL로 이동할 때 내 브라우저에서 성공적으로 호출되었기 때문에 이것을 사용했습니다. 그러나 불필요한 헤더도 제거하려고 시도했고 똑같이 예측할 수 없는 결과를 얻었습니다.

내 앱 할당량의 <1%에 있기 때문에 요청 제한과 아무 관련이 없는 것 같습니다. 나는 또한 cURL 요청 사이에 >10초를 기다리려고 시도했지만 결과에 영향을 미치지 않았습니다.

이상한 점은 내가 이것을 수행할 때마다 FB가 나에게 유효한 액세스 코드를 제공하는 것 같다는 것입니다. 실제 웹 브라우저에서 요청합니다. 이 문제는 내 PHP cURL 요청이 내 브라우저의 XHR 요청과 동일하더라도 cURL을 사용할 때만 존재합니다.


참조 솔루션

방법 1:

This is less of an answer and more of a workaround. I tried many different configurations with cURL ‑ none of them were reliable.

However I found one simple method to work 100% of the time, which was to use file_get_contents().

(by Wills ManleyWills Manley)

참조 문서

  1. Unreliable results while obtaining long‑lived token (CC BY‑SA 2.5/3.0/4.0)

#facebook-php-sdk #facebook #facebook-graph-api #facebook-opengraph #facebook-javascript-sdk






관련 질문

앱 사용자의 담벼락에 자신으로 게시하려면 액세스 토큰이 필요합니까? (Do you need an access token to post on app user's wall as themself?)

onclick 속성을 사용하여 어떻게 벽에 게시할 수 있습니까? (how can i post on a wall using onclick attribute?)

사용자의 담벼락에 게시하고 권한을 요청하는 다른 방법이 있습니까? (Are there different ways to post to user's wall and ask for permissions?)

모바일 장치에서 Facebook PHP SDK에 문제가 있음 (Having trouble with Facebook PHP SDK on mobile devices)

하나의 앱에서 각 페이지에 대해 다른 facebook 보안 페이지 탭 URL을 추가하는 방법 (How to add diffrent facebook Secure Page Tab URL for each page in one app)

모바일 클라이언트에서 서버 및 프로세스로 facebook 액세스 토큰 전달 (Pass facebook access token from mobile client to server and process)

페이지 팔로워 뉴스 피드에 Facebook 팬 페이지 콘텐츠가 표시되지 않음 (Facebook Fan page content not showing in page followers news feed)

이미지 없이 FB 공유 대화 상자 만들기 (Create FB share dialog without image)

Facebook 오류 #100: 사진 URL이 제공된 경우 링크를 제공해야 합니다. (Facebook Error #100 : A link must be provided if a picture URL is given)

맞춤 이벤트에서 웹사이트 맞춤 타겟을 만들려면 어떻게 해야 합니까? (How do I create a website Custom Audience from a custom event?)

수명이 긴 토큰을 얻는 동안 신뢰할 수 없는 결과 (Unreliable results while obtaining long-lived token)

갑자기 주석 플러그인 코드가 주석 상자를 표시하지 않습니다 (Suddenly Comments Plugin code is not showing commenting box)







코멘트