Skip to content

Commit

Permalink
Facebook access token added (Facebook API change)
Browse files Browse the repository at this point in the history
  • Loading branch information
xeraa committed Jun 5, 2011
1 parent 0a55a22 commit 5a5359d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
11 changes: 8 additions & 3 deletions code/FacebookFeedWidget.php
Expand Up @@ -63,8 +63,13 @@ public function Feeds(){

/**
* URL for fetchning the information, convert the returned JSON into an array.
* It is required to use an access_token which in turn mandates https.
*/
$url = 'http://graph.facebook.com/' . $this->Identifier . '/feed?limit=' . ($this->Limit + 5);
if(!defined('FACEBOOK_ACCESS_TOKEN')){
user_error('Missing Facebook access token - please get one and add it to your mysite/_config.php: define("FACEBOOK_ACCESS_TOKEN", "<your token>");', E_USER_WARNING);
return;
}
$url = 'https://graph.facebook.com/' . $this->Identifier . '/feed?limit=' . ($this->Limit + 5) . '&access_token=' . FACEBOOK_ACCESS_TOKEN;
$facebook = json_decode(file_get_contents($url), true);

/**
Expand All @@ -88,14 +93,14 @@ public function Feeds(){
/**
* If it isn't a post, but an event for example: continue with the next entry.
*/
if(!isset($post['from']['id']) || !isset($post['id']) || !isset($post['message'])){
if(!isset($post['from']['id']) || !isset($post['message'])){
continue;
}

/**
* If the post is from the user itself and not someone else, add the message and date to our feeds array.
*/
if(strpos($post['id'], $post['from']['id']) === 0){
if(strpos($this->Identifier, $post['from']['id']) === 0){
$posted = date_parse($post['created_time']);
$feeds->push(new ArrayData(array(
'Message' => DBField::create('Text', $post['message']),
Expand Down
22 changes: 12 additions & 10 deletions templates/FacebookFeedWidget.ss
@@ -1,13 +1,15 @@
<% if Limit == 0 %>
<% else %>
<div id="facebookfeed">
<h2><% if Limit == 1 %><% _t('UPDATE','Facebook Update') %><% else %><% _t('UPDATES','Facebook Updates') %><% end_if %></h2>
<% control Feeds %>
<p>
$Message.Parse(Nl2BrParser)<br/>
<small>$Posted.Nice</small>
</p>
<% if Last %><% else %><hr/><% end_if %>
<% end_control %>
</div>
<% if Feeds %>
<div id="facebookfeed">
<h2><% if Limit == 1 %><% _t('UPDATE','Facebook Update') %><% else %><% _t('UPDATES','Facebook Updates') %><% end_if %></h2>
<% control Feeds %>
<p>
$Message.Parse(Nl2BrParser)<br/>
<small>$Posted.Nice</small>
</p>
<% if Last %><% else %><hr/><% end_if %>
<% end_control %>
</div>
<% end_if %>
<% end_if %>

0 comments on commit 5a5359d

Please sign in to comment.