来自外部URL的Facebook事件个人资料图片
问题描述:
我正在尝试使用PHP创建Facebook事件。我有的最后一个问题是个人资料图片。
我的问题是:
我可以使用外部图片url的事件资料图片?
如果是,比如何?来自外部URL的Facebook事件个人资料图片
答
所以来自Lix的代码只是从一部分开始。但是这是一个完整的工作代码。
$externalImage = 'External link to image';
$tempImagePath = 'Local link to save image';
$user = 123456789; // USER ID
// save image
file_put_contents($tempImagePath, file_get_contents($externalImage));
// Create data for new event
$data = array(
'name' => 'Event title',
'description' => 'Event description',
'owner' => $user, // user as owner of this event
'location' => 'Location',
'start_time' => '2013-05-08T11:00:00-0700',
'end_time' => '2013-05-09T19:00:00-0700',
'@file.jpg' => '@'.realpath($tempImagePath),
'privacy_type' => 'OPEN'
);
// Create event
$eventID = $facebook->api('/'.$account.'/events', 'post', $data);
如果您有任何问题,请写信给我。
答
您将无法真正使用该URL作为个人资料图片发送,但如果您首先将其下载到服务器上,则可以使用该URL。 file_get_contents()
和file_put_contents()
的简单组合可以复制图像。
$externalImage = 'http://lorempixel.com/400/200/';
$tempImagePath = 'tmp/temp_image_path.jpg';
// save remote file to the server to $tempImagePath
file_put_contents($tempImagePath, file_get_contents($externalImage));
// upload the image to the event
$facebook->api("/EVENT_ID/picture", "POST",
array('source' => '@'. realpath($tempImagePath))
);
// remove temp image
unlink($tempImagePath);
+0
它不工作。错误:$ facebook-> api中的数组到字符串的转换请致电 – 2013-05-09 23:48:21
+0
其中一个参数提供的是一个数组,它应该是一个字符串。看看你指定的参数... – Lix 2013-05-10 06:59:50
这很奇怪,因为在事件创建过程中你可以使用参数“图片 - 事件图片的URL” – 2013-05-08 21:19:37
哦......对不起..我以为你是说你想要在外部托管图片... – Lix 2013-05-08 21:22:02