开发者

Creating facebook events via cron-job

I am trying to create facebook events via cron-job. The events should be created on behalf of users of my facebook-connect-site, who have granted offline-access. I have session_keys that do not expire, but can't get it to work! Creating events on behalf of my app works like a charm, is just not what I want...

var_dump($event) with some randomly generated data:
'name' => string 'Try a athirst these and' (length=23)
'tagline' => string 'as it that he down the almost the' (length=33)
'description' => string 'that deeper but is sea whenever lead all a stream knowing robust bakehouses attending have am it pent for own quick' (length=115)
'category' => int 5
'subcategory' => int 52
'location' => string 'same as 开发者_C百科more the' (length=16)
'start_time' => int 1263630600
'end_time' => int 1263654000
'street' => string 'This Was Ships My 807' (length=21)
'phone' => string '49 692 324' (length=10)
'email' => string 'oeott@yahoo.com' (length=15)
'privacy_type' => string 'OPEN' (length=4)

<?php

$facebook = new Fb(FACEBOOK_API_KEY, FACEBOOK_API_SECRET);
// Set session key (that has been returned after offline-access has been granted)
$facebook->api_client->session_key = '5de03e54cb359f9asf3435365e-4588985454';
$eid = $facebook->api_client->events_create(json_encode($event));

?>

Results in: "exception 'FacebookRestClientException' with message 'Invalid parameter'"

Is anyone out there able to save my day?


Assuming you have asked for the create_events extended permission, you should be able to do this with the new Open Graph API and the up-to-date PHP SDK. The code would be something like this (not tested):

$facebook = new Facebook(array(
  'appId'  => 'application ID',
  'secret' => 'application secret',
  'cookie' => true,
));
if ($session = $facebook->getSession()) {
  try {
    $event = $facebook->api("/me/events","post",array(
      'title'=>'My Event Name',
      'start_time'=>1263630600,
      'end_time'=>1263654000,
      // etc add your other event info here
    ));
  } catch (FacebookApiException $e) {
    error_log($e);
  }
}

It should run from as a CRON task as well, I don't know why it wouldn't.


Are you sure you need to use session key? I have been using access_token that is provided when access is granted for posting items to the wall and accessing user information offline.

edit: code example that works for me perfectly for posting items to user wall (events work alike):

<?php
$ch = curl_init ('https://graph.facebook.com/me/feed');
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, array('access_token' => $user_access_token, 'message' => $message, 'link' => $link));
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$ret = curl_exec ($ch);
$ret = json_decode($ret);
if (!empty($ret->id)) {
  return true;
}
return false;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜