This repository has been archived by the owner on Nov 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Add support for creating and deleting content with the Facebook Graph AP... #68
Open
mpitid
wants to merge
2
commits into
develop
Choose a base branch
from
feature/facebook-api
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
* | ||
* @category Libraries | ||
* @package Storyplayer/Prose | ||
* @author Michael Heap <[email protected]> | ||
* @author Michael Heap <[email protected]>, Michael Pitidis <[email protected]> | ||
* @copyright 2011-present Mediasift Ltd www.datasift.com | ||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://datasift.github.io/storyplayer | ||
|
@@ -72,21 +72,36 @@ class FromCurl extends Prose | |
*/ | ||
public function get($url, $params = array(), $headers = array()) | ||
{ | ||
return $this->request($url, $params, $headers); | ||
} | ||
|
||
public function post($url, $data, $params = array(), $headers = array()) | ||
{ | ||
return $this->request($url, $params, $headers, 'POST', array( | ||
CURLOPT_POST => true, | ||
CURLOPT_POSTFIELDS => $data, | ||
)); | ||
} | ||
|
||
public function delete($url, $params = array(), $headers = array()) | ||
{ | ||
return $this->request($url, $params, $headers, 'DELETE', array( | ||
CURLOPT_CUSTOMREQUEST => "DELETE", | ||
)); | ||
} | ||
|
||
protected function request($url, $params = array(), $headers = array(), $method = 'GET', $options = array()) { | ||
if (count($headers)){ | ||
throw new E5xx_NotImplemented("FromCurl does not support headers yet"); | ||
} | ||
|
||
// shorthand | ||
$st = $this->st; | ||
|
||
// create the full URL | ||
if (count($params) > 0) { | ||
$url = $url . '?' . http_build_query($params); | ||
} | ||
|
||
// what are we doing? | ||
$log = $st->startAction("HTTP GET '${url}'"); | ||
$log = $this->st->startAction("HTTP $method '${url}'"); | ||
|
||
// create a new cURL resource | ||
$ch = curl_init(); | ||
|
@@ -95,6 +110,9 @@ public function get($url, $params = array(), $headers = array()) | |
curl_setopt($ch, CURLOPT_URL, $url); | ||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | ||
curl_setopt($ch, CURLOPT_HEADER, 0); | ||
foreach ($options as $key => $val) { | ||
curl_setopt($ch, $key, $val); | ||
} | ||
|
||
// grab URL and pass it to the browser | ||
$response = curl_exec($ch); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,7 +35,7 @@ | |
* | ||
* @category Libraries | ||
* @package Storyplayer/Prose | ||
* @author Michael Heap <[email protected]> | ||
* @author Michael Heap <[email protected]>, Michael Pitidis <[email protected]> | ||
* @copyright 2011-present Mediasift Ltd www.datasift.com | ||
* @license http://www.opensource.org/licenses/bsd-license.php BSD License | ||
* @link http://datasift.github.io/storyplayer | ||
|
@@ -97,6 +97,28 @@ public function getLatestPostFromPage($id){ | |
return reset($posts); | ||
} | ||
|
||
public function getPostUpdatedTime($post_id) { | ||
return $this->st->fromCurl()->get("{$this->base_path}/{$post_id}", $this->authenticated(array( | ||
'fields' => 'updated_time', | ||
))); | ||
} | ||
|
||
public function createComment($post_id, $comment) { | ||
return $this->makeGraphPostRequest("/{$post_id}/comments", "message=$comment"); | ||
} | ||
|
||
public function deleteComment($comment_id) { | ||
return $this->makeGraphDeleteRequest("/{$comment_id}"); | ||
} | ||
|
||
private function makeGraphPostRequest($path, $data, $params = array()) { | ||
return $this->st->fromCurl()->post($this->base_path . $path, $data, $this->authenticated($params)); | ||
} | ||
|
||
private function makeGraphDeleteRequest($path, $params = array()) { | ||
return $this->st->fromCurl()->delete($this->base_path . $path, $this->authenticated($params)); | ||
} | ||
|
||
/** | ||
* makeGraphApiRequest | ||
* | ||
|
@@ -106,14 +128,12 @@ public function getLatestPostFromPage($id){ | |
* | ||
* @return void | ||
*/ | ||
private function makeGraphApiRequest($path){ | ||
private function makeGraphApiRequest($path, $params = array()){ | ||
$st = $this->st; | ||
|
||
$environment = $st->getEnvironment(); | ||
$access_token = $environment->facebookAccessToken; | ||
|
||
// GET $path/?access_token=$access_token | ||
$resp = $st->fromCurl()->get($this->base_path.$path.'?access_token='. $access_token); | ||
$resp = $st->fromCurl()->get($this->base_path . $path, $this->authenticated($params)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need to rename $this->authenticated to $this->addAccessToken |
||
|
||
// Make sure it's well formed | ||
$log = $st->startAction("make sure we have the 'data' key in the response"); | ||
|
@@ -136,4 +156,11 @@ private function makeGraphApiRequest($path){ | |
|
||
return $resp->data; | ||
} | ||
|
||
private function authenticated(array $params) { | ||
if (!isset($params['access_token'])) { | ||
$params['access_token'] = $this->st->getEnvironment()->facebookAccessToken; | ||
} | ||
return $params; | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be moved to usingCurl. fromCurl should only be for idempotent methods.