I am trying create Facebook event with PHP. The last problem which I have is profile picture.

My questions are:
Can I use external picture url for event profile picture??
If yes, than how??

有帮助吗?

解决方案 2

So the code from Lix works just from part. But here is an full working code.

$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); 

If you have some questions just write me.

其他提示

You won't be able to actually use that URL to send as the profile picture, but you will be able to use it if you first download it to your server. A simply combination of file_get_contents() and file_put_contents() can copy over the image.

$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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top