代码之家  ›  专栏  ›  技术社区  ›  JahStation

扩展larasap/fb post方法

  •  0
  • JahStation  · 技术社区  · 8 年前

    https://github.com/toolkito/laravel-social-auto-posting

    因为我的控制器的使用非常简单,而其他的软件包即使是像我需要实现的基本操作也会造成很大的混乱!

    目标:-在一个fb页面上发布一些用户标签的文本,这些标签都已经将一个like放到了同一个页面上。

    SendTo::Facebook(
     ‘link’,
     [
     ‘link’ => ‘https://github.com/toolkito/laravel-social-auto-posting',
     ‘message’ => ‘Laravel social auto posting’
     ]
    );
    

    如果我简单地剪掉链接部分,消息部分可以是我的文章,所有的工作都很容易。

    @[userId]
    

    这不起作用,标记部分被剪切,只显示文本: 如果我派 'text'=>'some text @[mineuserid] more text''

    '一些文本更多文本'

    就在墙上。

    所以我开始复制和扩展这些方法。 如果我完全理解fb文档,我可以用字段标记用户 tags 但即使是字段也需要指定 places (在这种情况下,如果我完全理解我的页面的id)

    所以我开始研究包,并尝试mods over send包的链接:

    public static function Facebook($type, $data)
        {
            switch ($type) {
                case 'link':
                    $message = isset($data['message']) ? $data['message'] : '';
                    $result = FacebookApi::sendLink($data['link'], $data['message']);
                    break;
    
                case 'postolo':
                    $message = isset($data['message']) ? $data['message'] :'';
                    $tags =isset($data['tags']) ? $data['tags'] : '';
                    $places =isset($data['places']) ? $data['places'] : '';
    
                    $result = FacebookApi::sendPostolo( $message, $tags,$places);
                    break;
    

    我的部分是“postolo”

    public static function sendLink($link, $message = '')
        {
            self::initialize();
            $data = compact('link', 'message');
            try {
                $response = self::$fb->post('/me/feed', $data, self::$page_access_token);
            } catch(Facebook\Exceptions\FacebookResponseException $e) {
                throw new \Exception('Graph returned an error: '.$e->getMessage());
            } catch(Facebook\Exceptions\FacebookSDKException $e) {
                throw new \Exception('Facebook SDK returned an error: '.$e->getMessage());
            }
            $graphNode = $response->getGraphNode();
    
            return $graphNode['id'];
        }
    

    如果我愚蠢地复制了这个并使它适应我的需要,就像:

     public static function sendPostolo($link, $message = '',$tags='',$places='')
        {
            self::initialize();
            $data = compact( 'tags','message','places');
            try {
                $response = self::$fb->post('/me/feed', $data, self::$page_access_token);
            } catch(Facebook\Exceptions\FacebookResponseException $e) {
                throw new \Exception('Graph returned an error: '.$e->getMessage());
            } catch(Facebook\Exceptions\FacebookSDKException $e) {
                throw new \Exception('Facebook SDK returned an error: '.$e->getMessage());
            }
            $graphNode = $response->getGraphNode();
    
            return $graphNode['id'];
        }
    

    这是fb包上的post():

     public function post($endpoint, array $params = [], $accessToken = null, $eTag = null, $graphVersion = null)
        {
            return $this->sendRequest(
                'POST',
                $endpoint,
                $params,
                $accessToken,
                $eTag,
                $graphVersion
            );
        }
    
    0 回复  |  直到 8 年前