From c932406f8b540b4407a0c470af0d1b7b68596ddc Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sun, 1 Mar 2009 11:57:41 -0500 Subject: [PATCH] Add a revokeExtendedPermissions method, move get_login_url to the Auth class and rename getLoginUrl, rename call_upload_method to callUploadMethod --- .../Service_Facebook/doc/facebook_example.php | 32 ++++++++++++--------- .../lib/Horde/Service/Facebook.php | 18 +++--------- .../lib/Horde/Service/Facebook/Auth.php | 33 ++++++++++++++++++++++ .../lib/Horde/Service/Facebook/Photos.php | 2 +- .../lib/Horde/Service/Facebook/Users.php | 2 +- 5 files changed, 58 insertions(+), 29 deletions(-) diff --git a/framework/Service_Facebook/doc/facebook_example.php b/framework/Service_Facebook/doc/facebook_example.php index c13e73574..ea43202d9 100644 --- a/framework/Service_Facebook/doc/facebook_example.php +++ b/framework/Service_Facebook/doc/facebook_example.php @@ -107,27 +107,33 @@ var_dump($result); * as a reference so when run() is called, you still have a handle to the * results. */ -$facebook->batchBegin(); -$notifications = &$facebook->notifications->get(); -$friends = &$facebook->friends->get(); -$facebook->batchEnd(); -var_dump($friends); -var_dump($notifications); +//$facebook->batchBegin(); +//$notifications = &$facebook->notifications->get(); +//$friends = &$facebook->friends->get(); +//$facebook->batchEnd(); +//var_dump($friends); +//var_dump($notifications); /** * View a user's pictures. $uid should be the user id whose albums you want to * retrieve. (Permissions permitting, of course) */ -$albums = $facebook->photos->getAlbums($uid); -var_dump($albums); -$images = $facebook->photos->get('', $albums[0]['aid']); -var_dump($images); +//$albums = $facebook->photos->getAlbums($uid); +//var_dump($albums); +//$images = $facebook->photos->get('', $albums[0]['aid']); +//var_dump($images); /** * Request the raw JSON (or XML) data */ -$facebook->dataFormat = Horde_Service_Facebook::DATA_FORMAT_JSON; -$results = $facebook->photos->getAlbums($uid); -var_dump($results); +//$facebook->dataFormat = Horde_Service_Facebook::DATA_FORMAT_JSON; +//$results = $facebook->photos->getAlbums($uid); +//var_dump($results); +/** + * Upload a photo + */ +$path = "/Users/mrubinsk/Desktop/horde_fb.jpg" +$results = $facebook->photos->upload($path); +var_dump($results); \ No newline at end of file diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook.php b/framework/Service_Facebook/lib/Horde/Service/Facebook.php index d4dfb190d..9c1e93aa0 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook.php @@ -4,8 +4,9 @@ * rest interface. * * This code was originally a Hordified version of Facebook's official PHP - * client. However, very little of the original code or design is left. I left - * the original copyright notice intact below. + * client. However, since that client was very buggy and incomplete, very little + * of the original code or design is left. I left the original copyright notice + * intact below. * * Copyright 2009 The Horde Project (http://www.horde.org) * @@ -240,17 +241,6 @@ class Horde_Service_Facebook } /** - * Return a valid FB login URL with necessary GET parameters appended. - * - * @return string - */ - public function get_login_url($next) - { - return self::getFacebookUrl() . '/login.php?v=1.0&api_key=' - . $this->_apiKey . ($next ? '&next=' . urlencode($next) : ''); - } - - /** * Start a batch operation. */ public function batchBegin() @@ -327,7 +317,7 @@ class Horde_Service_Facebook * * @return array A dictionary representing the response. */ - public function call_upload_method($method, $params, $file) + public function callUploadMethod($method, $params, $file) { if ($this->_batchRequest === null) { if (!file_exists($file)) { diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Auth.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Auth.php index 82b0a4e72..2b513a151 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook/Auth.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Auth.php @@ -64,6 +64,17 @@ class Horde_Service_Facebook_Auth } /** + * Return a valid FB login URL with necessary GET parameters appended. + * + * @return string + */ + public function getLoginUrl($next) + { + return Horde_Service_Facebook::getFacebookUrl() . '/login.php?v=1.0&api_key=' + . $this->_apiKey . ($next ? '&next=' . urlencode($next) : ''); + } + + /** * Returns the URL for a user to obtain the auth token needed to generate an * infinite session for a web app. * @@ -419,4 +430,26 @@ class Horde_Service_Facebook_Auth $this->_sessionKey = $sessionKey; $this->_session_expires = $expires; } + + /** + * Revoke a previously authorizied extended permission + * + * @param $perm + * @param $uid + * @return unknown_type + */ + public function revokeExtendedPermission($perm, $uid) + { + // Session key is *required* + if (!$skey = $this->getSessionKey()) { + throw new Horde_Service_Facebook_Exception('session_key is required', + Horde_Service_Facebook_ErrorCodes::API_EC_SESSION_REQUIRED); + } + + return $this->_facebook->callMethod('Auth.revokeExtendedPermission', + array('session_key' => $skey, + 'perm' => $perm, + 'user' => $uid)); + + } } \ No newline at end of file diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php index 15b06e832..506691c4f 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Photos.php @@ -277,7 +277,7 @@ class Horde_Service_Facebook_Photos extends Horde_Service_Facebook_Base if ($this->_facebook->dataFormat == Horde_Service_Facebook::DATA_FORMAT_ARRAY) { $oldFormat = $this->_facebook->setInternalFormat(Horde_Service_Facebook::DATA_FORMAT_XML); } - $results = $this->_facebook->call_upload_method('facebook.photos.upload', $params, $file); + $results = $this->_facebook->callUploadMethod('facebook.photos.upload', $params, $file); if (!empty($oldFormat)) { $this->_facebook->setInternalFormat($oldFormat); } diff --git a/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php b/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php index 11c2fe2aa..95bb4364e 100644 --- a/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php +++ b/framework/Service_Facebook/lib/Horde/Service/Facebook/Users.php @@ -32,7 +32,7 @@ class Horde_Service_Facebook_Users extends Horde_Service_Facebook_Base * authorized your application will be returned. * * Check the wiki for fields that can be queried through this API call. - * Data returned from here should not be used for rendering to application + * Data returned from here should *not* be used for rendering to application * users, use users.getInfo instead, so that proper privacy rules will be * applied. * -- 2.11.0