代碼示例,上傳封面照片時創建事件:
<?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);
?>
在這個崗位的答案爲我工作:http://stackoverflow.com/questions/15725574/facebook-php-sdk-upload-event-cover-photo – kaore