Skip to content

Commit

Permalink
Merge pull request #7 from sascha53/master
Browse files Browse the repository at this point in the history
Added possibility to use User Access Token for fetching owner's page
  • Loading branch information
xmhafiz authored Dec 14, 2018
2 parents 4649035 + 9c5e237 commit 60d0f0f
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/FbFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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');
}


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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';
Expand Down

0 comments on commit 60d0f0f

Please sign in to comment.