Php 在facebook上获取最终图形图片url

Php 在facebook上获取最终图形图片url,php,image,facebook-graph-api,redirect,http-status-code-403,Php,Image,Facebook Graph Api,Redirect,Http Status Code 403,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

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 pagespeed),我开始缓存“最终”url,如下所示:

$preview = get_redirect_url('https://graph.facebook.com/'.$uid.'/picture');
if(!$preview){ 
        /* fallback */
        $preview = 'https://graph.facebook.com/'.$uid.'/picture';
}
在哪里

这在一段时间内效果很好,但现在facebook禁止访问以下网址:

"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) {
  }
}
您可以使用图片作为参数之一来创建一个链接,它将为您提供最新的“最终”链接


它仍然需要2个调用,但您将避免重定向。可能快一点

你好,谢谢你的回答!我用更多的代码编辑了这个问题,这样你们就知道我在什么阶段请求“最终”url了。那么你的意思是在缓存时进行fql查询,还是每次都进行fql查询。我认为“最终”url会随着时间的推移而变化,因此很难在较长的时间内对其进行缓存。问题是,在我展示的其中25个页面中,也许使用图形url更容易?你是说25个用户的25张图片?更好!您可以一次获得所有URL。类似于:从用户中选择名称、uid、pic_square,其中uid in(“+fids+”)应该起作用
$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) {
  }
}