我正在开发一个小型应用程序,该应用程序允许用户从他的 Facebook 相册中选择一张照片,最好是从个人资料或封面相册中选择。
我正在使用以下代码。测试网址http://babysoftblog.com/megapicture/albums.php
<?php
$app_id = 'XXXXX';
$app_secret = 'XXXXX';
$my_url = 'http://babysoftblog.com/megapicture/albums.php';
$code = $_REQUEST["code"];
// auth user
if(empty($code)) {
$dialog_url = 'https://www.facebook.com/dialog/oauth/?client_id='.$app_id.'&redirect_uri='.urlencode($my_url).'&scope=user_photos';
echo("<script>top.location.href='" . $dialog_url . "'</script>");
}
//get user access_token
$token_url = 'https://graph.facebook.com/oauth/access_token?client_id='
. $app_id . '&redirect_uri=' . urlencode($my_url)
. '&client_secret=' . $app_secret
. '&code=' . $code;
try {
$access_token = file_get_contents(@$token_url);
}
catch (Exception $e)
{ echo "OOPs look like something went wrong"; }
//$fql_query_url = 'https://graph.facebook.com/'.'fql?q=SELECT+pid,src_small+FROM+photo+WHERE+aid+IN+(SELECT+aid+FROM+album+WHERE+owner=+me())&'.$access_token;
try{
$fql_query_url = 'https://graph.facebook.com/'.'fql?q=SELECT+aid,name+FROM+album+WHERE+owner=+me()&'.$access_token;
$fql_query_result = file_get_contents($fql_query_url);
$fql_query_obj = json_decode($fql_query_result, true);
}
catch (Exception $e)
{ echo "oops something went wrong"; }
?>
但是当我刷新页面时使用上面的代码..它给出了异常,请参见这里 http://babysoftblog.com/megapicture/albums.php 以及如何直接选择个人资料和封面相册的照片。
请帮助我,在此先感谢。