如何将这些数据发送到Facebook? Facebook api照片上传
问题描述:
好的,facebook要我发送本地存储在服务器上的图像,但是我将图像存储在数据库的BLOB中...
Okay so facebook want me to send an image stored locally on the server but i have the images stored in a BLOB in the database...
try {
$file = 'http://blaze-craft.com/matt/get.php?id=' . $lastid;
$post_data = array(
"message" => "Uploaded using the Funnymemes app!",
"source" => $file
);
$data['photo'] = $facebook->api("/me/photos", 'post', $post_data);
}
catch (FacebookApiException $e) {
}
但是它没有上传...我从facebook api doc那里获得了这段代码,所以我不确定发生了什么事情
but its not uploading... I got this code from the facebook api doc's so im not sure whats going on?
有什么想法吗?
答
要使照片上传正常工作,您必须解决以下问题:
In order to photo upload to work you have to fix these:
- 图像文件应存储在文件系统中(即将BLOB保存回 磁盘)
- 在
$post_data
数组中的图像路径之前使用@
.
- Image files should be stored in filesystem (i.e. save BLOB back to the disk)
- Use
@
before image path in$post_data
array.
为此,我会做类似的事情:
For this purpose i would do something like:
try
{
$url = 'http://blaze-craft.com/matt/get.php?id=' . $lastid;
$saveas = '/images/image.jpg';
$res = @file_put_contents($saveas, file_get_contents($url));
if($res === false) throw new Exception('Cannot fetch image');
$post_data = array(
"message" => "Uploaded using the Funnymemes app!",
"source" => '@' . $saveas;
);
$data['photo'] = $facebook->api("/me/photos", 'post', $post_data);
}
catch (FacebookApiException $e) { }
catch (Exception $e) { }