本文整理汇总了PHP中Facebook::post方法的典型用法代码示例。如果您正苦于以下问题:PHP Facebook::post方法的具体用法?PHP Facebook::post怎么用?PHP Facebook::post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Facebook
的用法示例。
在下文中一共展示了Facebook::post方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __call
/**
* Handle postTo* methods.
*
* @param string $method
* @param array $arguments
*/
function __call($method, $arguments)
{
if (text($method)->startsWith('get')) {
// a get*($parameters) method?
if (empty($this->id)) {
throw new \Exception('Can\'t fetch a connection without an id');
}
if (count($arguments) > 0) {
$parameters = $arguments[0];
} else {
$parameters = array();
}
$connection = lcfirst(substr($method, 3));
$connections = $this->getKnownConnections(array('id' => $this->id));
if (isset($connections[$connection]['class'])) {
$class = $connections[$connection]['class'];
} else {
$class = '\\Sledgehammer\\GraphObject';
}
if (isset($connections[$connection]['permission']) && $connections[$connection]['permission'] !== 'denied' && in_array($connections[$connection]['permission'], Facebook::getInstance()->getPermissions()) === false) {
notice('Connection "' . $connection . '" requires the "' . $connections[$connection]['permission'] . '" permission', 'Current permissions: ' . quoted_human_implode(' and ', Facebook::getInstance()->getPermissions()));
}
$objects = array();
$response = Facebook::all($this->id . '/' . $connection, $parameters);
foreach ($response as $data) {
$objects[] = new $class($data);
}
if (empty($arguments['fields'])) {
foreach ($objects as $object) {
$object->_state = 'partial';
}
}
return new Collection($objects);
}
if (text($method)->startsWith('postTo')) {
// a postTo*($data) method?
if (empty($this->id)) {
throw new \Exception('Can\'t post to a connection without an id');
}
if (count($arguments) > 0) {
$parameters = $arguments[0];
} else {
notice('Missing argument 1 for ' . $method . '()');
$parameters = array();
}
$response = Facebook::post($this->id . '/' . lcfirst(substr($method, 6)), $parameters);
return new GraphObject($response['id']);
} else {
return parent::__call($method, $arguments);
}
}
示例2: postToFacebook
protected function postToFacebook($confession, $user = null)
{
if (env('MANUAL_MODE', false)) {
return 0;
}
if ($confession->images) {
if ($confession->fb_post_id) {
$endpoint = '/' . $confession->fb_post_id;
} else {
$endpoint = '/' . env('FACEBOOK_PAGE_ID', '') . '/photos';
}
$response = \Facebook::post($endpoint, ['message' => $confession->getFacebookMessage(), 'url' => $confession->images], $this->getPageToken($user))->getGraphObject();
if ($confession->fb_post_id) {
return $confession->fb_post_id;
} else {
return $response['id'];
}
} else {
if ($confession->fb_post_id) {
$endpoint = '/' . env('FACEBOOK_PAGE_ID', '') . '_' . $confession->fb_post_id;
} else {
$endpoint = '/' . env('FACEBOOK_PAGE_ID', '') . '/feed';
}
$response = \Facebook::post($endpoint, ['message' => $confession->getFacebookMessage()], $this->getPageToken($user))->getGraphObject();
if ($confession->fb_post_id) {
return $confession->fb_post_id;
} else {
return explode('_', $response['id'])[1];
}
}
}