大家好,我正在尝试了解如何从Facebook上传图片。
执行fql查询的功能。适用于未来的场合。
<?php
// connection facebook api key...
function fb_fql($fql) {
$this->ci =& get_instance();
// Get User Details
$this->ci->load->model('facebook_model');
$this->ci->load->library('user');
// $fb_id = $this->ci->user->get_facebook_id($this->ci->session->userdata('user_id'));
// User is found
// Get Facebook User profile
$user_profile = $this->ci->facebook->getUser();
$result = false;
if ($user_profile) { // if profile exist
try{
$accessToken = $this->ci->facebook->getAccessToken();
$fb_id = $this->ci->facebook->api('/me?access_token='.$accessToken);
if( isset($user_profile) )
{
$fql_run = array(
'method' => 'fql.query',
'query' => $fql,
);
$result = $this->ci->facebook->api($fql_run); // run fql
} else { $result = false; }
}catch(FacebookApiException $e){
$result = null;
}
}
return $result;
}
?>
在这里,我通过此查询得到照片,阵列的结果正确显示了Facebook的10张照片。现在我必须将它上传到我的服务器上,但我该怎么办呢?
<?php
// fql query
$fql = "SELECT pid
FROM photo
WHERE aid IN (
SELECT aid
FROM album
WHERE owner=me() LIMIT 10
) ";
// run query
$photos = $this->facebook_action->fb_fql($fql);
if ($photos != false) {
foreach ($photos as $photo) {
echo print_r($photos); // show the array with the data taken
// here i would like upload the photos got from the query.
}
} else {
echo "no photo";
}
?>
答案 0 :(得分:0)
您需要从照片表中获取src或src_big字段,然后使用CURL,file_put_contents或类似内容下载它。 StackOverflow有很多答案可以抓取图像并将其保存到文件中 - 例如Saving image from PHP URL
SELECT src_big FROM photo
WHERE aid IN (SELECT aid FROM album WHERE owner=me() LIMIT 10)
由于您要将用户数据下载到自己的服务器,我建议您检查您的应用程序是否违反了Facebook Platform Policy。