[英]Facebook Graph-API using curl - Create event with picture failed
I have tested the codes from this and this but it doesn't work. 我已经测试从码本和这个 ,但它不工作。
The event is created successfully but the image is not published. 事件创建成功,但是图像未发布。
Here is my actual code: 这是我的实际代码:
require_once '../admini/config.php';
$t = getToken('appID', 'appSecret');
$file = 'Koala.jpg';
$arrData = array(
'name' => 'Test Event',
'start_time' => '2015-07-04', //ISO-8601 format - With Time - 2012-07-04T19:00:00-0700
//'end_time' => '', //optional
'description' => 'Das erste Test-Event',
'location' => 'Deggendorf', //Just a name
'location_id' => '103091806397289', //place id - inserts a link to place fb page
'ticket_url' => 'url', //URL to buy a ticket for the event
'no_feed_story' => FALSE, //TRUE = dont display on page
'access_token' => 'token',
'picture' => '@'. realpath($file),
);
$createUrl = 'https://graph.facebook.com/page_id/events';
$test = fbcurl($createUrl, 'POST', $arrData); //Returns the event id
echo '<pre>';
print_r($test);
echo '</pre>';
function fbcurl($url, $method, $fields = array(), $auth = array()){
foreach($fields as $key => $value){
if(!is_string($value)){
$fields[$key] = json_encode($value);
}
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:multipart/form-data'));
// curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method);
// if(count($auth)===2)
// curl_setopt($ch, CURLOPT_USERPWD, $auth['user'].':'.$auth['pass']);
// }
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if(count($fields)>0){
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields, null, '&'));
}
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
//curl_setopt($ch, CURLOPT_TIMEOUT, 60);
//curl_setopt($ch, CURLOPT_USERAGENT, 'facebook-php-3.2');
//curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "Content-Type: multipart/form-data");
//file_put_contents('fbcurllocal.txt', print_r(http_build_query($fields, null, '&'), true)."\n".$url);
$r = curl_exec($ch);
curl_close($ch);
if($r!=''){
$p = explode("\r\n\r\nHTTP/", $r);
$p = (count($p) > 1 ? 'HTTP/' : '') . array_pop($p);
list($h, $b) = explode("\r\n\r\n", $p, 2);
return array('header' => $h, 'body' => $b);
}else{
return array('header' => '', 'body' => 'error');
}
}
If you read the documentation , ther's no such field picture
with \\POST /{page-id}/events
. 如果您阅读了文档 ,则没有
\\POST /{page-id}/events
这样的领域picture
。
So, while creating an event you can not publish a cover picture along with it. 因此,在创建事件时,您无法随其一起发布封面图片。 So it's a two-step procedure-
这是一个两步过程-
Create event 建立活动
API: \\POST /{page-id}/events
- Reference API:
\\POST /{page-id}/events
参考
This you've already done, just delete the picture
parameter from there. 您已经完成此操作,只需从此处删除
picture
参数即可。
Upload cover picture 上传封面图片
API: \\POST /{event-id}/events
- Reference API:
\\POST /{event-id}/events
参考
Give the image to the parameter: source
将图像赋予参数:
source
This way you can upload the cover pic to an event. 这样,您可以将封面图片上传到活动中。 Hope that helps.
希望能有所帮助。
Edit 编辑
The method to upload cover photo that I've mentioned will not work as of now (you can subscribe to this bug to get the update), instead you'll be needing a link to the image and make the call- 到目前为止,我提到的上传封面照片的方法目前无法使用(您可以订阅此错误以获取更新),而是需要链接到该图像并进行呼叫-
\POST /{event-id}
Parameter: cover_url
参数:
cover_url
This works. 这可行。 I've tested!
我测试过了!
look at the commtens before to understand it. 在理解之前先看一下命令。
'asdf' => '@'. realpath($file).';type=image/jpeg',
(
[header] => HTTP/1.1 200 OK
x-fb-rev: 1200162
Access-Control-Allow-Origin: *
Cache-Control: private, no-cache, no-store, must-revalidate
Content-Type: application/json; charset=UTF-8
Date: Thu, 10 Apr 2014 14:26:20 GMT
Expires: Sat, 01 Jan 2000 00:00:00 GMT
Pragma: no-cache
X-FB-Debug: nLKpXn4cbeF4AMa8kiOVMAfcKG5EFvQZmqvxFJXYC88=
Connection: keep-alive
Content-Length: 4
[body] => true
)
i tested this 我测试了
'source' => '@'. realpath($file).';type=image/jpeg',
and this 和这个
'source' => '@'. realpath($file),
bevore bevore
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.