代码示例,创建事件时上传封面照片:
<?php
//extract data from the post
extract($_POST);
//set POST variables
$url = 'https://graph.facebook.com/me/events';
$data["file"] = "@pika.jpg;type=image/jpeg";
$data["access_token"] = "PUT_USER_ACCESS_TOKEN_HERE";
$data["name"] = "testing";
$data["start_time"] = "2013-04-25";
$data["end_time"] = "2013-04-25";
$data["description"] = "coffee";
$data["location"] = "oldtown";
$data["privacy_type"] = "FRIENDS";
//make the POST request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data; boundary=--$srand");
//close connection
curl_close($ch);
?>
代码示例,创建事件后,您还可以通过上传新照片来替换封面照片:
<?php
//extract data from the post
extract($_POST);
//set POST variables
$url = 'https://graph.facebook.com/PUT_EVENT_ID_HERE';
$data["file"] = "@pikachu.jpg;type=image/jpeg";
$data["access_token"] = "PUT_USER_ACCESS_TOKEN_HERE";
//make the POST request
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_VERBOSE, 1);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
//close connection
curl_close($ch);
?>