public function post($objectId, $msg, $link = '', $name = '', $caption = '', $description = '', $picture = '') { $result = new \stdClass(); $result->id = null; $result->url = null; $result->error = null; /* if ( !$this->authenticated || !$this->api ) { $result->error = "Facebook user not authenticated."; return $result; } */ $attachment = array('message' => $msg, 'link' => $link, 'name' => $name, 'caption' => $caption, 'description' => $description, 'picture' => $picture, 'privacy' => json_encode(array('value' => 'EVERYONE'))); // TODO: allow choice of EVERYONE, CUSTOM, ALL_FRIENDS, NETWORKS_FRIENDS, FRIENDS_OF_FRIENDS, SELF. Log::debug("attachment: " . print_r($attachment, true)); $publication = new \Kiki\Publication(); $publication->setObjectId($objectId); $publication->setConnectionId($this->externalId); $publication->setBody(serialize($attachment)); try { $fbRs = $this->api()->api('/me/feed', 'post', $attachment); } catch (Exception $e) { Log::error("Exception: {$e}"); } catch (FacebookApiException $e) { $result->error = $e; Log::debug("error: {$result->error}"); return $result; } $publication->setResponse(serialize($fbRs)); if (isset($fbRs['id'])) { $result->id = $fbRs['id']; list($uid, $postId) = explode("_", $fbRs['id']); $result->url = "//www.facebook.com/{$uid}/posts/{$postId}"; $publication->setExternalId($postId); } else { $result->error = $fbRs; Log::debug("error: {$result->error}"); } $publication->save(); return $result; }
public function post($objectId, $msg, $link = '', $name = '', $caption = '', $description = '', $picture = '') { $result = new \stdClass(); $result->id = null; $result->url = null; $result->error = null; /* if ( !$this->authenticated || !$this->api ) { $result->error = "Twitter user not authenticated."; return $result; } */ \Kiki\Log::debug("msg: {$msg}"); try { $twRs = $this->api()->post('statuses/update', array('status' => $msg)); } catch (Exception $e) { \Kiki\Log::error("Exception: {$e}"); } $publication = new \Kiki\Publication(); $publication->setObjectId($objectId); $publication->setConnectionId($this->externalId); $publication->setBody($msg); $publication->setResponse(serialize($twRs)); $publication->setExternalId(isset($twRs->id) ? $twRs->id : 0); $publication->save(); if (!$twRs) { $result->error = "Twitter status update failed."; return $result; } if (isset($twRs->errors)) { $result->error = $twRs->errors->message; \Kiki\Log::debug("twPost error: {$result->errors}->message"); } else { $result->id = $twRs->id; $result->url = "//www.twitter.com/" . $twRs->user->screen_name . "/status/" . $result->id; } return $result; }