From 4bb860a2fab2560ec4d3bb55b12835787fb07cdd Mon Sep 17 00:00:00 2001 From: Mohd Hafiz Date: Fri, 14 Dec 2018 15:44:10 +0800 Subject: [PATCH] update readme and examples for using userAccessToken --- README.md | 10 ++++++++++ example/index.php | 16 +++++++++++++--- src/FbFeed.php | 5 ++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index d100e7f..1809560 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,16 @@ $data = fb_feed()->setAppId($fbAppId) ->fetch(); ``` +#### To get owner's fb page feed using userAccessToken + +Details to get `userAccessToken` can refer [here](https://github.com/xmhafiz/fb-page-feed/pull/7). + +```php +$data = fb_feed() + ->setAccessToken($userAccessToken) + ->setPage($fbPageName) + ->fetch(); +``` ## Code Example diff --git a/example/index.php b/example/index.php index 362f75f..f9039b4 100644 --- a/example/index.php +++ b/example/index.php @@ -19,15 +19,25 @@ $fbSecretKey = getenv('FB_SECRET_KEY'); $fbAppId = getenv('FB_APP_ID'); $fbPageName = getenv('FB_PAGENAME'); +$accessToken = getenv('FB_ACCESS_TOKEN'); +// Example 1 $response = fb_feed()->setAppId($fbAppId)->setSecretKey($fbSecretKey)->setPage($fbPageName)->findKeyword("#tutorial")->fetch(); -//or +// Example 2 $response = fb_feed()->setCredential($fbAppId, $fbSecretKey)->setPage($fbPageName)->findKeyword("#tutorial")->fetch(); -//or + +// Example 3 $response = fb_feed()->findKeyword("#tutorial")->fetch(); -//or + +// Example 4 $response = fb_feed()->findKeyword(['#tutorial', '#tips'])->fetch(); +// Example 5 - to fetch owner's pages only. Apps review not required +$response = fb_feed()->setAccessToken($accessToken)->fetch(); + +// Example 6 +$response = fb_feed()->fetch(); + header('Content-type: application/json'); echo json_encode($response, JSON_PRETTY_PRINT); \ No newline at end of file diff --git a/src/FbFeed.php b/src/FbFeed.php index a4f9242..05ba8f7 100644 --- a/src/FbFeed.php +++ b/src/FbFeed.php @@ -30,7 +30,6 @@ public function __construct() $this->access_token = getenv('FB_ACCESS_TOKEN'); } - /** * @param $app_id * @return $this @@ -115,11 +114,11 @@ function fetch() { return $this->returnFailed('Page Name is needed'); } - if (!$this->app_id&&!$this->access_token) { + 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&&!$this->access_token) { + if (!$this->secret_key &&! $this->access_token) { return $this->returnFailed('Facebook Secret Key is needed. Please refer to https://developers.facebook.com'); }