创建一个Facebook活动并发布封面照片 [英] Creating a facebook event and publishing a cover photo
问题描述
$ param = array(
'name '=> $ name,
'start_time'=> $ ate,
'description'=> $ description,
'picture'=> $ photo
) ;
$ facebook-> api('/ me / events','POST',$ param);
是否可以为在此呼叫中创建的事件设置封面照片?
如果没有,我可以设置它吗?
文档说封面字段需要一个照片ID。
如果我还没有上传照片,它没有ID,那我该怎么办?
我是否将照片上传到发布创建事件动作的用户的facebok帐户,获取照片ID,然后发布到活动?
如果我不想要将其上传到用户个人资料?
谢谢
代码示例,创建事件时上传封面照片:
<?php
//从帖子中提取数据
提取($ _ POST);
//设置POST变量
$ 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] =咖啡;
$ data [location] =oldtown;
$ data [privacy_type] =FRIENDS;
//使POST请求
$ 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);
//关闭连接
curl_close($ ch);
?>
代码示例,事件创建后,您还可以通过上传新照片替换封面照片:
<?php
//从帖子中提取数据
extract($ _ POST);
//设置POST变量
$ url ='https://graph.facebook.com/PUT_EVENT_ID_HERE';
$ data [file] =@ pikachu.jpg; type = image / jpeg;
$ data [access_token] =PUT_USER_ACCESS_TOKEN_HERE;
//使POST请求
$ 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_close($ ch);
?>
I'm creating a facebook event through the php sdk using
$param = array(
'name' => $name,
'start_time' => $ate,
'description' => $description,
'picture' => $photo
);
$facebook->api('/me/events', 'POST', $param);
Is it possible to set a cover photo for the event that is being created at this call? If not, can I set it somehow?
The documentation says that the cover field needs a photo id. If I haven't uploaded the photo yet, it doesn't have an id, so what do I do?
Do I upload the photo to the facebok account of user that issuing the "create event" action, getting that way the photo id, and then post it to the event?
What if I don't want to upload it to the users profile?
Thank you
Code example, upload cover photo when create event:
<?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);
?>
Code example, After event created, you can also replace cover photo by upload new photo:
<?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);
?>
这篇关于创建一个Facebook活动并发布封面照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!