Facebook 이미지는
https://graph.facebook.com/{uid}/picture
문제는 이것이 다음과 같은 URL로 리디렉션된다는 것입니다.
https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xfa1/v/t1.0-1/c0.0.50.50/p50x50/10264431_865630423451069_7413030211804680043_n.jpg?oh=96840deb90665b0b5ee39a77591fb521&oe=546D8360&__gda__=1416463680_c
따라서 리디렉션을 방지하기 위해 (기본적으로 더 나은 Google 페이지 속도 정보를 얻기 위해) 다음과 같이 "최종"URL을 캐싱하기 시작했습니다.
$preview = get_redirect_url('https://graph.facebook.com/'.$uid.'/picture');
if(!$preview){
/* fallback */
$preview = 'https://graph.facebook.com/'.$uid.'/picture';
}
어디
function get_redirect_url($url){
$redirect_url = null;
$url_parts = @parse_url($url);
if (!$url_parts) return false;
if (!isset($url_parts['host'])) return false; //can't process relative URLs
if (!isset($url_parts['path'])) $url_parts['path'] = '/';
$sock = fsockopen($url_parts['host'], (isset($url_parts['port']) ? (int)$url_parts['port'] : 80), $errno, $errstr, 30);
if (!$sock) return false;
$request = "HEAD " . $url_parts['path'] . (isset($url_parts['query']) ? '?'.$url_parts['query'] : '') . " HTTP/1.1\r\n";
$request .= 'Host: ' . $url_parts['host'] . "\r\n";
$request .= "Connection: Close\r\n\r\n";
fwrite($sock, $request);
$response = '';
while(!feof($sock)) $response .= fread($sock, 8192);
fclose($sock);
if (preg_match('/^Location: (.+?)$/m', $response, $matches)){
if ( substr($matches[1], 0, 1) == "/" )
return $url_parts['scheme'] . "://" . $url_parts['host'] . trim($matches[1]);
else
return trim($matches[1]);
} else {
return false;
}
}
그리고 그것은 한동안 훌륭하게 작동하고 있었지만 이제는 페이스 북 이이 URL에 대한 액세스를 금지하고 있습니다.
"NetworkError: 403 Forbidden - https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xap1/v/t1.0-1/c0.0.50.50/p50x50/10645271_1540579909486778_4851323870004250654_n.jpg?oh=10622ec9a388b684a1232afff0c11389&oe=547A2A4D&__gda__=1415381628_"
그리고 최악의 부분은 내가 설정 한 "대체"가 403 상태 코드에서도 트리거되지 않는다는 것입니다.
그래서 질문은
해결 방법을 알고 있습니까?
-편집하다-
더 많은 코드 :
$session = $facebook->getUser()>0;
$access_token = 'access_token='.$facebook->getAccessToken();
$app_access_token = file_get_contents('https://graph.facebook.com/oauth/access_token?client_id=123456789&client_secret=a1b2c3d4e5f6&grant_type=client_credentials');
$me = null;
if ($session) {
try {
$uid = $facebook->getUser();
$me = $facebook->api('/me');
/*Obtener info del usuario*/
$pageContent = file_get_contents("https://graph.facebook.com/".$uid);
$parsedJson = json_decode($pageContent, true);
/*Agregar a base de datos si no existe*/
$r = new registro_usuarios();
$preview = get_redirect_url('https://graph.facebook.com/'.$uid.'/picture');
if(!$preview){
$preview = 'https://graph.facebook.com/'.$uid.'/picture';
}
$r->facebook($uid,$me['name'],$preview,$me['email']); /* register user */
} catch (FacebookApiException $e) {
}
}
대신 그림을 매개 변수 중 하나로 사용하여 FQL 쿼리 를 만들 수 있습니다. 그러면 가장 최근의 "최종"링크가 제공됩니다.
여전히 2 번의 호출이 필요하지만 리디렉션을 피할 수 있습니다. 조금 더 빠를 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다