Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added possibility to use Page Access Token #7

Merged
merged 1 commit into from
Dec 14, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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