Rubenwouters\CrmLauncher\ApiCalls\FetchFacebookContent::publishPost PHP Method

publishPost() public method

Publish post
public publishPost ( string $post ) : array | Illuminate\View\View
$post string
return array | Illuminate\View\View
    public function publishPost($post)
    {
        $fb = initFb();
        $token = $this->config->FbAccessToken();
        try {
            $publishment = $fb->post('/' . config('crm-launcher.facebook_credentials.facebook_page_id') . '/feed?&message=' . $post, ['access_token' => $token]);
            return json_decode($publishment->getBody());
        } catch (Exception $e) {
            getErrorMessage($e->getCode());
            return back();
        }
    }

Usage Example

 /**
  * Publish Tweet and/or Facebook post
  *
  * @param  Request $request
  *
  * @return view
  */
 public function publish(Request $request)
 {
     $this->validate($request, ['content' => 'required', 'social' => 'required']);
     $content = rawurlencode($request->input('content'));
     if (in_array(self::TYPE_TWITTER, $request->input('social'))) {
         $publishment = $this->twitterContent->publishTweet($content);
         $this->insertPublishment(self::TYPE_TWITTER, $publishment, $content);
     }
     if (in_array(self::TYPE_FACEBOOK, $request->input('social'))) {
         $publishment = $this->facebookContent->publishPost($content);
         $this->insertPublishment(self::TYPE_FACEBOOK, $publishment, $content);
     }
     return back();
 }