當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Facebook::post方法代碼示例

本文整理匯總了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);
     }
 }
開發者ID:sledgehammer,項目名稱:facebook,代碼行數:57,代碼來源:GraphObject.php

示例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];
         }
     }
 }
開發者ID:nekonekonik,項目名稱:nuswhispers,代碼行數:31,代碼來源:ConfessionsRepository.php


注:本文中的Facebook::post方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。