How to get a securl cover URL?

丶灬走出姿态 提交于 2019-12-11 13:18:48

问题


I'm tryng to get the cover url of a FBpage using:

$fql_query_url = "https://graph.facebook.com"
    ."/$fb_id[id]?fields=cover"
."";
try {
    $fql_query_result = @file_get_contents($fql_query_url);
    $fql_query_obj = json_decode($fql_query_result, true);
} catch(Exception $o){   }
$cover = $fql_query_obj[cover][source];

I get an http://... url and not the https://... url

any tips?


回答1:


As @CBroe pointed out, you need to specify you need a secure URL by setting the return_ssl_resources argument to 1: https://graph.facebook.com/wtf.no.username/picture?return_ssl_resources=1.

Edit: Please note that this isn't FQL (Facebook Query Language), this is just a standard API call.




回答2:


After getting the url, you can replace http to https with preg_replace() in PHP.

$cover = $fql_query_obj[cover][source];
$secure_cover = preg_replace('/^http(?=:\/\/)/i','https',$cover);

As far as i tested, it works fine.

You can also change this with javascript.

cover = cover.replace(/^http:\/\//i, 'https://');

hope this help someone :)



来源:https://stackoverflow.com/questions/13702442/how-to-get-a-securl-cover-url

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!