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

newestConversationId() public method

Get newest conversation id
public newestConversationId ( ) : integer | boolean | Illuminate\View\View
return integer | boolean | Illuminate\View\View
    public function newestConversationId()
    {
        $fb = initFb();
        $token = $this->config->FbAccessToken();
        try {
            $privates = $fb->get('/' . config('crm-launcher.facebook_credentials.facebook_page_id') . '/conversations?fields=id,updated_time&limit=1', $token);
            $posts = json_decode($privates->getBody());
            if (count($posts->data)) {
                return $posts->data[0]->id;
            }
            return false;
        } catch (Exception $e) {
            getErrorMessage($e->getCode());
            return back();
        }
    }

Usage Example

 /**
  * Get most recent id's for Twitter & Facebook
  *
  * @return void
  */
 private function initIds()
 {
     $message = new Message();
     if (isTwitterLinked()) {
         $mentionId = $this->twitterContent->newestMentionId();
         $directId = $this->twitterContent->newestDirectId();
         if ($mentionId) {
             $message->tweet_id = $mentionId;
         }
         if ($directId) {
             $message->direct_id = $directId;
         }
     }
     if (isFacebookLinked()) {
         $postId = $this->facebookContent->newestPostId();
         $conversationId = $this->facebookContent->newestConversationId();
         if ($postId) {
             $message->fb_post_id = $postId;
         }
         if ($conversationId) {
             $message->fb_private_id = $conversationId;
         }
     }
     $message->post_date = Carbon::now();
     $message->save();
     $this->log->updateLog('fetching');
 }