Skip to content

Commit

Permalink
facebook update
Browse files Browse the repository at this point in the history
  • Loading branch information
voitto committed Apr 11, 2010
1 parent 0e95105 commit 01ccb4b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 34 deletions.
2 changes: 1 addition & 1 deletion app/facebook/plugins/facebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function send_to_facebook( &$model, &$rec ) {

//$fb->api_client->session_key = $sesskey;
//$fb->api_client->user = $uid;
$fs = new FacebookStream($consumer_key,$consumer_secret,$agent);
$fs = new FacebookStream($consumer_key,$consumer_secret,$agent,$app_id);

// $fs->api->sessionKey = $sesskey;
$fs->setSess($sesskey);
Expand Down
12 changes: 6 additions & 6 deletions app/omb/plugins/security.php
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ function facebook_login( &$vars ) {
$_SESSION['fb_session'] = (string)$fb->api_client->session_key;
$_SESSION['fb_userid'] = (string)$fb->user;

$fs = new FacebookStream($consumer_key,$consumer_secret,$agent);
$fs = new FacebookStream($consumer_key,$consumer_secret,$agent,$app_id);

$token = $fs->getAccessToken();

Expand All @@ -1038,7 +1038,7 @@ function facebook_login( &$vars ) {

$fields = implode(',',$fieldlist);

$user = $fs->GetInfo( $app_id, $_SESSION['fb_session'], $_SESSION['fb_userid'], $fields );
$user = $fs->GetInfo( $_SESSION['fb_userid'], $fields );

$values = array();

Expand Down Expand Up @@ -1606,7 +1606,7 @@ function facebook_timeline(&$vars){
require_once "facebook.php";

$fb = new Facebook($consumer_key, $consumer_secret, true);
// $fs = new FacebookStream($consumer_key,$consumer_secret,$agent);
// $fs = new FacebookStream($consumer_key,$consumer_secret,$agent,$app_id);
$facebook->api_client->session_key = $sesskey;
$facebook->api_client->user = $userid;
$data = $fb->api_client->stream_get();
Expand All @@ -1617,7 +1617,7 @@ function facebook_timeline(&$vars){

// $access_token = $db->result_value($result,0,'oauth_key');

$fs = new FacebookStream($consumer_key,$consumer_secret,$agent);
$fs = new FacebookStream($consumer_key,$consumer_secret,$agent,$app_id);
$fs->VerifyPerm($userid,'offline_access');

$hash = md5("app_id=".$appid."session_key=".$sesskey."source_id=".$userid.$fs->getApiSecret());
Expand Down Expand Up @@ -1666,7 +1666,7 @@ function facebook_timeline(&$vars){

$sesskey = $_SESSION['fb_session'];

$user = $fs->GetInfo($appid,$_SESSION['fb_session'],$userid,$fields);
$user = $fs->GetInfo($userid,$fields);

$hash = md5("app_id=".$appid."session_key=".$sesskey."source_id=".$userid.$fs->getApiSecret());

Expand Down Expand Up @@ -1719,7 +1719,7 @@ function facebook_timeline(&$vars){

$fields = implode(',',$fieldlist);

$user = $fs->GetInfo($appid,$_SESSION['fb_session'],$userid,$fields);
$user = $fs->GetInfo($userid,$fields);
print_r($user); exit;

$fs->StreamRequest( $app_id, $_SESSION['fb_session'], $userid );
Expand Down
61 changes: 34 additions & 27 deletions db/library/facebook_stream/FacebookStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class FacebookStream {
private $last_api_call;
private $api;
private $agent;
private $appid;

/**
* construct FacebookStream object
*/
function __construct($consumer_key, $consumer_secret, $agent) {
function __construct($consumer_key, $consumer_secret, $agent, $appid) {

/* Set Facebook key/secret */
Services_Facebook::$apiKey = $consumer_key;
Expand All @@ -32,6 +33,8 @@ function __construct($consumer_key, $consumer_secret, $agent) {
$this->api = new Services_Facebook();

$this->agent = $agent;

$this->appid = $appid;

}

Expand All @@ -55,7 +58,14 @@ function getAccessToken() {
function getApiKey() {
return Services_Facebook::$apiKey;
}


/**
* Return the session Key
*/
function getSessionKey() {
return $this->api->sessionKey;
}

/**
* Return the API secret
*/
Expand Down Expand Up @@ -88,48 +98,45 @@ function permanent_facebook_key($key,$secret){
/**
* Facebook Stream API request
*/
function StreamRequest($appid,$sesskey,$userid) {

//$this->verifyPerms(array('read_stream'),$userid);
function StreamRequest($userid) {

$hash = md5("app_id=".$appid."session_key=".$sesskey."source_id=".$userid.$this->getApiSecret());

$url = 'http://www.facebook.com/activitystreams/feed.php';
$url .= '?source_id=';
$url .= $userid;
$url .= '&app_id=';
$url .= $appid;
$url .= '&session_key=';
$url .= $sesskey;
$url .= '&sig=';
$url .= $hash;
$url .= '&v=0.7&read';

echo $this->http($url);

exit;
// requires read_stream
$hash = md5("app_id=".$this->appid."session_key=".$this->getSessionKey()."source_id=".$userid.$this->getApiSecret());

$url = 'http://www.facebook.com/activitystreams/feed.php';
$url .= '?source_id=';
$url .= $userid;
$url .= '&app_id=';
$url .= $this->appid;
$url .= '&session_key=';
$url .= $this->getSessionKey();
$url .= '&sig=';
$url .= $hash;
$url .= '&v=0.7&read';

return $this->http($url);

}

function GetInfo($appid,$sesskey,$userid,$fields) {
function GetInfo($userid,$fields) {

// http://wiki.developers.facebook.com/index.php/Users.getInfo

$params = array(
'api_key' => $this->getApiKey(),
'call_id' => microtime(true),
'sig' => md5("app_id=".$appid."session_key=".$sesskey."source_id=".$userid.$this->getApiSecret()),
'sig' => md5("app_id=".$this->appid."session_key=".$this->getSessionKey()."source_id=".$userid.$this->getApiSecret()),
'v' => '1.0',
'uids' => $userid,
'fields' => $fields,
'session_key' => $sesskey
'session_key' => $this->getSessionKey()
);

return $this->api->users->callMethod( 'users.getInfo', $params );

}

function verifyPerms($perms,$userid,$path='') {
function verifyPerms($userid,$perms,$path='') {

$showperms = array();

Expand All @@ -153,7 +160,7 @@ function verifyPerms($perms,$userid,$path='') {

function setStatus($status,$userid) {

//$this->verifyPerms(array('status_update','photo_upload'),$userid);
//$this->verifyPerms($userid,array('status_update','photo_upload'));

$params = array(
'uid' => $userid,
Expand All @@ -173,7 +180,7 @@ function setStatus($status,$userid) {

function PhotoUpload( $file, $aid=0, $caption='',$userid ) {

//$this->verifyPerms(array('status_update','photo_upload'),$userid);
//$this->verifyPerms($userid,array('status_update','photo_upload'));

$params = array(
'method' => 'photos.upload',
Expand Down

0 comments on commit 01ccb4b

Please sign in to comment.