From 9c5e237aa3be572ca59e3426ca10d922ad2fa0f7 Mon Sep 17 00:00:00 2001 From: Sascha Date: Thu, 13 Dec 2018 11:47:04 +0100 Subject: [PATCH] Added setAccessToken --- src/FbFeed.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/FbFeed.php b/src/FbFeed.php index eb4fce7..a4f9242 100644 --- a/src/FbFeed.php +++ b/src/FbFeed.php @@ -17,6 +17,7 @@ class FbFeed { private $keyword = null; private $limit = 100; // all of it private $fields = 'id,message,created_time,from,permalink_url,full_picture'; + private $access_token = null; /** * FbFeed constructor. @@ -26,6 +27,7 @@ public function __construct() $this->secret_key = getenv('FB_SECRET_KEY'); $this->app_id = getenv('FB_APP_ID'); $this->page_name = getenv('FB_PAGENAME'); + $this->access_token = getenv('FB_ACCESS_TOKEN'); } @@ -57,6 +59,15 @@ function setSecretKey ($secret_key) { $this->secret_key = $secret_key; return $this; } + + /** + * @param $access_token + * @return $this + */ + function setAccessToken ($access_token) { + $this->access_token = $access_token; + return $this; + } /** * @param $fields @@ -104,16 +115,16 @@ function fetch() { return $this->returnFailed('Page Name is needed'); } - if (!$this->app_id) { + if (!$this->app_id&&!$this->access_token) { return $this->returnFailed('Facebook App ID is needed. Please refer to https://developers.facebook.com'); } - if (!$this->secret_key) { + if (!$this->secret_key&&!$this->access_token) { return $this->returnFailed('Facebook Secret Key is needed. Please refer to https://developers.facebook.com'); } - + // this is how to construct access token using secret key and app id - $accessToken = $this->app_id . '|' . $this->secret_key; + $accessToken = $this->access_token ? $this->access_token : $this->app_id . '|' . $this->secret_key; // make request as stated in https://developers.facebook.com/docs/graph-api/using-graph-api $url = 'https://graph.facebook.com/' . $this->page_name . '/feed';