├── lib └── facebook-php-sdk-v4-4.0-dev │ ├── .gitignore │ ├── tests │ ├── FacebookTestCredentials.php.dist │ ├── GraphLocationTest.php │ ├── GraphUserTest.php │ ├── GraphSessionInfoTest.php │ ├── FacebookCanvasLoginHelperTest.php │ ├── FacebookJavaScriptLoginHelperTest.php │ ├── FacebookPageTabHelperTest.php │ ├── bootstrap.php │ ├── HttpClients │ │ ├── AbstractTestHttpClient.php │ │ ├── FacebookGuzzleHttpClientTest.php │ │ └── FacebookStreamHttpClientTest.php │ ├── GraphAlbumTest.php │ ├── FacebookTestHelper.php │ ├── FacebookRedirectLoginHelperTest.php │ ├── FacebookSignedRequestFromInputHelperTest.php │ ├── FacebookSessionTest.php │ ├── GraphObjectTest.php │ ├── FacebookRequestTest.php │ └── Entities │ │ ├── SignedRequestTest.php │ │ └── AccessTokenTest.php │ ├── CONTRIBUTING.md │ ├── phpunit.xml.dist │ ├── composer.json │ ├── LICENSE │ ├── docs │ ├── FacebookCanvasLoginHelper.fbmd │ ├── retrieve_user_profile.fbmd │ ├── FacebookRequestException.fbmd │ ├── FacebookJavaScriptLoginHelper.fbmd │ ├── post_links.fbmd │ ├── FacebookRequest.fbmd │ ├── upload_photo.fbmd │ ├── FacebookRedirectLoginHelper.fbmd │ ├── FacebookResponse.fbmd │ ├── sdk_landing_page.fbmd │ ├── FacebookSession.fbmd │ ├── sdk_getting_started.fbmd │ └── GraphObject.fbmd │ ├── src │ └── Facebook │ │ ├── FacebookSDKException.php │ │ ├── FacebookOtherException.php │ │ ├── FacebookClientException.php │ │ ├── FacebookServerException.php │ │ ├── FacebookThrottleException.php │ │ ├── FacebookPermissionException.php │ │ ├── FacebookAuthorizationException.php │ │ ├── FacebookJavaScriptLoginHelper.php │ │ ├── FacebookCanvasLoginHelper.php │ │ ├── GraphPage.php │ │ ├── HttpClients │ │ ├── FacebookHttpable.php │ │ ├── FacebookStream.php │ │ ├── FacebookCurl.php │ │ ├── FacebookGuzzleHttpClient.php │ │ ├── FacebookStreamHttpClient.php │ │ └── FacebookCurlHttpClient.php │ │ ├── GraphUserPage.php │ │ ├── GraphLocation.php │ │ ├── FacebookPageTabHelper.php │ │ ├── GraphSessionInfo.php │ │ ├── GraphUser.php │ │ ├── FacebookSignedRequestFromInputHelper.php │ │ ├── GraphAlbum.php │ │ ├── GraphObject.php │ │ ├── FacebookResponse.php │ │ ├── FacebookRequestException.php │ │ ├── FacebookRedirectLoginHelper.php │ │ ├── FacebookRequest.php │ │ └── Entities │ │ └── SignedRequest.php │ ├── README.md │ └── autoload.php ├── config.php ├── logs.txt ├── README.md ├── LICENSE.md └── FacebookAutoPilot.php /lib/facebook-php-sdk-v4-4.0-dev/.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | composer.lock 3 | composer.phar 4 | .DS_Store 5 | .idea/ 6 | tests/FacebookTestCredentials.php 7 | 8 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookTestCredentials.php.dist: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /logs.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Posting to Facebook Walls [2015-08-23 04:04:35pm] 5 | ---------------------------------------- 6 | SUCCESS: posting message to http://www.facebook.com/groups/408300809376888 7 | SUCCESS: posting message to http://www.facebook.com/groups/159135974236413 8 | 9 | 10 | Posting to Facebook Walls [2015-08-23 04:17:48pm] 11 | ---------------------------------------- 12 | SUCCESS: posting message to http://www.facebook.com/groups/408300809376888 -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Contributing 2 | ------------ 3 | 4 | For us to accept contributions you will have to first have signed the 5 | [Contributor License Agreement](https://developers.facebook.com/opensource/cla). 6 | 7 | When committing, keep all lines to less than 80 characters, and try to 8 | follow the existing style. 9 | 10 | Before creating a pull request, squash your commits into a single commit. 11 | 12 | Add the comments where needed, and provide ample explanation in the 13 | commit message. 14 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 9 | 10 | 11 | ./tests 12 | 13 | 14 | 15 | 16 | ./src/Facebook 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/GraphLocationTest.php: -------------------------------------------------------------------------------- 1 | execute()->getGraphObject(); 18 | $this->assertTrue($response instanceof GraphObject); 19 | 20 | $location = $response->getProperty('location', GraphLocation::className()); 21 | $this->assertTrue(is_float($location->getLatitude())); 22 | $this->assertTrue(is_float($location->getLongitude())); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/GraphUserTest.php: -------------------------------------------------------------------------------- 1 | execute()->getGraphObject(GraphUser::className()); 17 | 18 | $info = FacebookTestHelper::$testSession->getSessionInfo(); 19 | 20 | $this->assertTrue($response instanceof GraphUser); 21 | $this->assertEquals($info->getId(), $response->getId()); 22 | $this->assertNotNull($response->getName()); 23 | $this->assertNotNull($response->getLastName()); 24 | $this->assertNotNull($response->getLink()); 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/GraphSessionInfoTest.php: -------------------------------------------------------------------------------- 1 | FacebookTestHelper::$testSession->getToken() 14 | ); 15 | $response = (new FacebookRequest( 16 | new FacebookSession(FacebookTestHelper::getAppToken()), 17 | 'GET', 18 | '/debug_token', 19 | $params 20 | ))->execute()->getGraphObject(GraphSessionInfo::className()); 21 | $this->assertTrue($response instanceof GraphSessionInfo); 22 | $this->assertNotNull($response->getAppId()); 23 | $this->assertTrue($response->isValid()); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookCanvasLoginHelperTest.php: -------------------------------------------------------------------------------- 1 | helper = new FacebookCanvasLoginHelper('123', 'foo_app_secret'); 14 | } 15 | 16 | public function testSignedRequestDataCanBeRetrievedFromPostData() 17 | { 18 | $_POST['signed_request'] = $this->rawSignedRequestAuthorized; 19 | 20 | $rawSignedRequest = $this->helper->getRawSignedRequest(); 21 | 22 | $this->assertEquals($this->rawSignedRequestAuthorized, $rawSignedRequest); 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookJavaScriptLoginHelperTest.php: -------------------------------------------------------------------------------- 1 | rawSignedRequestAuthorized; 15 | 16 | $helper = new FacebookJavaScriptLoginHelper($this->appId, $this->appSecret); 17 | 18 | $rawSignedRequest = $helper->getRawSignedRequest(); 19 | 20 | $this->assertEquals($this->rawSignedRequestAuthorized, $rawSignedRequest); 21 | } 22 | 23 | } 24 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "facebook/php-sdk-v4", 3 | "description": "Facebook SDK for PHP", 4 | "keywords": ["facebook", "sdk"], 5 | "type": "library", 6 | "homepage": "https://github.com/facebook/facebook-php-sdk-v4", 7 | "license": "Facebook Platform", 8 | "authors": [ 9 | { 10 | "name": "Facebook", 11 | "homepage": "https://github.com/facebook/facebook-php-sdk-v4/contributors" 12 | } 13 | ], 14 | "require": { 15 | "php": ">=5.4.0" 16 | }, 17 | "require-dev": { 18 | "phpunit/phpunit": "3.7.*", 19 | "mockery/mockery": "dev-master", 20 | "guzzlehttp/guzzle": "~4.0" 21 | }, 22 | "suggest": { 23 | "guzzlehttp/guzzle": "Allows for implementation of the Guzzle HTTP client" 24 | }, 25 | "autoload": { 26 | "psr-4": { 27 | "Facebook\\": "src/Facebook/" 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Facebook-Auto-Pilot 2 | Automate common Facebook activities such as posting to groups & pages walls. 3 | 4 | Link: https://www.darwinmail.app 5 | 6 | This script makes use of the Facebook API to effortlessly carry out certain tasks. 7 | * Post to groups your a member or an admin of. 8 | * Post to pages your a member or an admin of. 9 | * Set the max delay in seconds between api requests (posting). 10 | * Set the max amount of groups to post on in one run of this script. 11 | 12 | # How to Use 13 | 1. Simply open up 'config.php' 14 | 2. Create a new facebook app at https://developers.facebook.com/apps 15 | 3. Browse to your newly created app 16 | 4. Copy in your appID and appSecret to your file in step one 17 | 5. Make sure to set your apps 'Site URL' to http://localhost if your running the script locally 18 | 19 | # Future 20 | In the near future I plan to add many more types of Facebook functions. 21 | 22 | * Stay tuned! 23 | 24 | Feel free to Fork ;) 25 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookPageTabHelperTest.php: -------------------------------------------------------------------------------- 1 | rawSignedRequestAuthorized; 13 | $helper = new FacebookPageTabHelper('123', 'foo_app_secret'); 14 | 15 | $this->assertTrue($helper->isLiked()); 16 | $this->assertFalse($helper->isAdmin()); 17 | $this->assertEquals('42', $helper->getPageId()); 18 | $this->assertEquals('42', $helper->getPageData('id')); 19 | $this->assertEquals('default', $helper->getPageData('foo', 'default')); 20 | } 21 | 22 | } 23 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Facebook, Inc. 2 | 3 | You are hereby granted a non-exclusive, worldwide, royalty-free license to 4 | use, copy, modify, and distribute this software in source code or binary 5 | form for use in connection with the web services and APIs provided by 6 | Facebook. 7 | 8 | As with any software that integrates with the Facebook platform, your use 9 | of this software is subject to the Facebook Developer Principles and 10 | Policies [http://developers.facebook.com/policy/]. This copyright notice 11 | shall be included in all copies or substantial portions of the software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 16 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookCanvasLoginHelper.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookCanvasLoginHelper for the Facebook SDK for PHP 3 | 4 | A helper class for getting a FacebookSession in a Canvas app 5 | 6 | 7 | 8 | ## Facebook\FacebookCanvasLoginHelper {#overview} 9 | 10 | If your app is loaded through Canvas, Facebook sends a POST request with a signed request. This helper class will handle processing and validating that information with Facebook, and returns a `FacebookSession`. 11 | 12 | Usage: 13 | 14 | ~~~~ 15 | 16 | $helper = new FacebookCanvasLoginHelper(); 17 | try { 18 | $session = $helper->getSession(); 19 | } catch (FacebookRequestException $ex) { 20 | // When Facebook returns an error 21 | } catch (\Exception $ex) { 22 | // When validation fails or other local issues 23 | } 24 | if ($session) { 25 | // Logged in. 26 | } 27 | 28 | ~~~~ 29 | 30 | 31 | 32 | ## Instance Methods {#instance-methods} 33 | 34 | ### getSession {#getsession} 35 | `getSession()` 36 | Processes the POST request from Facebook, if present. Returns a `FacebookSession` or `null`. 37 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Joey Tawadrous 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/retrieve_user_profile.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # Retrieve User Profile via the Graph API 3 | 4 | This example covers getting profile information for the current user and printing their name, using the Graph API and the Facebook SDK for PHP. 5 | 6 | It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php). 7 | 8 | For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`GraphUser`](/docs/php/GraphObject/#user-instance-methods), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException). 9 | 10 | 11 | 12 | 13 | 14 | ~~~~ 15 | use Facebook\FacebookRequest; 16 | use Facebook\GraphUser; 17 | use Facebook\FacebookRequestException; 18 | 19 | if($session) { 20 | 21 | try { 22 | 23 | $user_profile = (new FacebookRequest( 24 | $session, 'GET', '/me' 25 | ))->execute()->getGraphObject(GraphUser::className()); 26 | 27 | echo "Name: " . $user_profile->getName(); 28 | 29 | } catch(FacebookRequestException $e) { 30 | 31 | echo "Exception occured, code: " . $e->getCode(); 32 | echo " with message: " . $e->getMessage(); 33 | 34 | } 35 | 36 | } 37 | ~~~~ 38 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookSDKException.php: -------------------------------------------------------------------------------- 1 | 2 | # FacebookRequestException for the Facebook SDK for PHP 3 | 4 | Represents an exception thrown by executing a Facebook request. 5 | 6 | 7 | 8 | ## Facebook\FacebookRequestException {#overview} 9 | 10 | This base class has several subclasses: 11 | 12 | `FacebookAuthorizationException` 13 | `FacebookClientException` 14 | `FacebookPermissionException` 15 | `FacebookServerException` 16 | `FacebookThrottleException` 17 | `FacebookOtherException` 18 | 19 | Whenever a FacebookRequestException is thrown, it will be one of these types. 20 | They are derived from the error information here: https://developers.facebook.com/docs/graph-api/using-graph-api/#errors 21 | 22 | 23 | 24 | ## Instance Methods {#instance-methods} 25 | 26 | `FacebookRequestException` extends from the base `\Exception` class, so `getCode()` and `getMessage()` are available by default. 27 | 28 | ### getHttpStatusCode {#gethttpstatus} 29 | `getHttpStatusCode()` 30 | Returns the HTTP status code returned with this exception. 31 | ### getSubErrorCode {#getsuberrorcode} 32 | `getSubErrorCode()` 33 | Returns the numeric sub-error code returned from Facebook. 34 | ### getErrorType {#geterrortype} 35 | `getErrorType()` 36 | Returns the type of error as a string. 37 | ### getResponse {#getresponse} 38 | `getResponse()` 39 | Returns the decoded response used to create the exception. 40 | ### getRawResponse {#getrawresponse} 41 | `getRawResponse()` 42 | Returns the raw response used to create the exception. 43 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookJavaScriptLoginHelper.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookJavaScriptLoginHelper for the Facebook SDK for PHP 3 | 4 | A helper class for getting a FacebookSession using the session from the Facebook SDK for JavaScript. 5 | 6 | 7 | 8 | ## Facebook\FacebookJavaScriptLoginHelper {#overview} 9 | 10 | If your web app uses the Facebook SDK for JavaScript, you can access that in your PHP code as well. This helper class will process and validate the cookie data used by the Facebook SDK for JavaScript, returning a `FacebookSession` on success. 11 | 12 | Usage: 13 | 14 | ~~~~ 15 | 16 | $helper = new FacebookJavaScriptLoginHelper(); 17 | try { 18 | $session = $helper->getSession(); 19 | } catch(FacebookRequestException $ex) { 20 | // When Facebook returns an error 21 | } catch(\Exception $ex) { 22 | // When validation fails or other local issues 23 | } 24 | if ($session) { 25 | // Logged in. 26 | } 27 | 28 | ~~~~ 29 | 30 | It's important to note that on first access, or if a session has since expired, these methods will operate on data that is one request-cycle stale. You will likely want to make an Ajax request when the login state changes in the Facebook SDK for JavaScript. Information about that here: (FB.event.subscribe)[https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/#events] 31 | 32 | 33 | 34 | ## Instance Methods {#instance-methods} 35 | 36 | ### getSession {#getsession} 37 | `getSession()` 38 | Processes the data available from the Facebook SDK for JavaScript, if present. Returns a `FacebookSession` or `null`. 39 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/post_links.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # Post Links Using the Graph API 3 | 4 | This example covers posting a link to the current user's timeline using the Graph API and Facebook SDK for PHP. 5 | 6 | It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php). You must have requested the `publish_actions` scope when logging in the user for this to work. 7 | 8 | For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException). 9 | 10 | 11 | 12 | 13 | 14 | ~~~~ 15 | use Facebook\FacebookRequest; 16 | use Facebook\GraphObject; 17 | use Facebook\FacebookRequestException; 18 | 19 | if($session) { 20 | 21 | try { 22 | 23 | $response = (new FacebookRequest( 24 | $session, 'POST', '/me/feed', array( 25 | 'link' => 'www.example.com', 26 | 'message' => 'User provided message' 27 | ) 28 | ))->execute()->getGraphObject(); 29 | 30 | echo "Posted with id: " . $response->getProperty('id'); 31 | 32 | } catch(FacebookRequestException $e) { 33 | 34 | echo "Exception occured, code: " . $e->getCode(); 35 | echo " with message: " . $e->getMessage(); 36 | 37 | } 38 | 39 | } 40 | ~~~~ 41 | 42 | Note that the 'message' field must come from the user, as pre-filled content is forbidden by the [Platform Policies](https://developers.intern.facebook.com/policy/#control) (2.3). 43 | 44 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/HttpClients/AbstractTestHttpClient.php: -------------------------------------------------------------------------------- 1 | 'HTTP/1.1 200 OK', 27 | 'Etag' => '"9d86b21aa74d74e574bbb35ba13524a52deb96e3"', 28 | 'Content-Type' => 'text/javascript; charset=UTF-8', 29 | 'X-FB-Rev' => '9244768', 30 | 'Pragma' => 'no-cache', 31 | 'Expires' => 'Sat, 01 Jan 2000 00:00:00 GMT', 32 | 'Connection' => 'close', 33 | 'Date' => 'Mon, 19 May 2014 18:37:17 GMT', 34 | 'X-FB-Debug' => '02QQiffE7JG2rV6i/Agzd0gI2/OOQ2lk5UW0=', 35 | 'Content-Length' => '29', 36 | 'Cache-Control' => 'private, no-cache, no-store, must-revalidate', 37 | 'Access-Control-Allow-Origin' => '*', 38 | ); 39 | 40 | } 41 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookJavaScriptLoginHelper.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookJavaScriptLoginHelper extends FacebookSignedRequestFromInputHelper 33 | { 34 | 35 | /** 36 | * Get raw signed request from the cookie. 37 | * 38 | * @return string|null 39 | */ 40 | public function getRawSignedRequest() 41 | { 42 | return $this->getRawSignedRequestFromCookie(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookRequest.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookRequest for the Facebook SDK for PHP 3 | 4 | Represents a request that will be made against the Graph API. 5 | 6 | 7 | 8 | ## Facebook\FacebookRequest {#overview} 9 | 10 | Constructor: 11 | 12 | ~~~~ 13 | $request = new FacebookRequest( 14 | FacebookSession $session, 15 | string $httpMethod, 16 | string $path, 17 | array $params = NULL, 18 | string $version = NULL 19 | ); 20 | ~~~~ 21 | 22 | Usage: 23 | 24 | ~~~~ 25 | // Make a new request and execute it. 26 | try { 27 | $response = (new FacebookRequest($session, 'GET', '/me'))->execute(); 28 | $object = $response->getGraphObject(); 29 | echo $object->getProperty('name'); 30 | } catch (FacebookRequestException $ex) { 31 | echo $ex->getMessage(); 32 | } catch (\Exception $ex) { 33 | echo $ex->getMessage(); 34 | } 35 | 36 | // You can chain methods together and get a strongly typed GraphUser 37 | $me = (new FacebookRequest( 38 | $session, 'GET', '/me' 39 | ))->execute()->getGraphObject(GraphUser::className); 40 | echo $me->getName(); 41 | ~~~~ 42 | 43 | 44 | 45 | ## Instance Methods {#instance-methods} 46 | 47 | ### execute {#execute} 48 | `execute()` 49 | Returns a `Facebook\FacebookResponse` from this request, from which a strongly-typed result can be retrieved. Throws an exception if the request fails. If the error is returned from Facebook, as opposed to a networking issue, a `Facebook\FacebookRequestException` is thrown. 50 | ### getPath {#getpath} 51 | `getPath()` 52 | Returns a copy of the path for the request, not including the version. 53 | ### getParameters {#getparams} 54 | `getParameters()` 55 | Returns a copy of the parameters array for the request. 56 | ### getSession {#getsession} 57 | `getSession()` 58 | Returns the `Facebook\FacebookSession` object associated with this request. 59 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/GraphAlbumTest.php: -------------------------------------------------------------------------------- 1 | self::ALBUM_NAME, 21 | 'message' => self::ALBUM_DESCRIPTION, 22 | 'value' => 'everyone' 23 | ) 24 | ))->execute()->getGraphObject(); 25 | 26 | $albumId = $response->getProperty('id'); 27 | 28 | $response = ( 29 | new FacebookRequest( 30 | FacebookTestHelper::$testSession, 31 | 'GET', 32 | '/'.$albumId 33 | ))->execute()->getGraphObject(GraphAlbum::className()); 34 | 35 | $this->assertTrue($response instanceof GraphAlbum); 36 | $this->assertEquals($albumId, $response->getId()); 37 | $this->assertTrue($response->getFrom() instanceof \Facebook\GraphUser); 38 | $this->assertTrue($response->canUpload()); 39 | $this->assertEquals(0, $response->getCount()); 40 | $this->assertEquals(self::ALBUM_NAME, $response->getName()); 41 | $this->assertEquals(self::ALBUM_DESCRIPTION, $response->getDescription()); 42 | $this->assertNotNull($response->getLink()); 43 | $this->assertNotNull($response->getPrivacy()); 44 | 45 | $type = array("profile", "mobile", "wall", "normal", "album"); 46 | $this->assertTrue(in_array($response->getType(),$type)); 47 | 48 | date_default_timezone_set('GMT'); 49 | $this->assertTrue($response->getCreatedTime() instanceof DateTime); 50 | $this->assertTrue($response->getUpdatedTime() instanceof DateTime); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/upload_photo.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # Upload Photos to a User's Profile 3 | 4 | This example covers uploading a photo to the current User's profile using the Graph API and the Facebook SDK for PHP. 5 | 6 | It assumes that you've already set your default app id and secret, and acquired a `FacebookSession` using an access token or one of the login helper classes found [here](/docs/php). You must have requested the `publish_actions` scope when logging in the user for this to work. 7 | 8 | For more information, see the documentation for [`GraphObject`](/docs/php/GraphObject), [`FacebookRequest`](/docs/php/FacebookRequest), and [`FacebookRequestException`](/docs/php/FacebookRequestException). 9 | 10 | 11 | 12 | 13 | 14 | ~~~~ 15 | use Facebook\FacebookRequest; 16 | use Facebook\GraphObject; 17 | use Facebook\FacebookRequestException; 18 | 19 | if($session) { 20 | 21 | try { 22 | 23 | // Upload to a user's profile. The photo will be in the 24 | // first album in the profile. You can also upload to 25 | // a specific album by using /ALBUM_ID as the path 26 | $response = (new FacebookRequest( 27 | $session, 'POST', '/me/photos', array( 28 | 'source' => new CURLFile('path/to/file.name', 'image/png'), 29 | 'message' => 'User provided message' 30 | ) 31 | ))->execute()->getGraphObject(); 32 | 33 | // If you're not using PHP 5.5 or later, change the file reference to: 34 | // 'source' => '@/path/to/file.name' 35 | 36 | echo "Posted with id: " . $response->getProperty('id'); 37 | 38 | } catch(FacebookRequestException $e) { 39 | 40 | echo "Exception occured, code: " . $e->getCode(); 41 | echo " with message: " . $e->getMessage(); 42 | 43 | } 44 | 45 | } 46 | ~~~~ 47 | 48 | Note that the 'message' field must come from the user, as pre-filled content is forbidden by the [Platform Policies](https://developers.intern.facebook.com/policy/#control) (2.3). 49 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookCanvasLoginHelper.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookCanvasLoginHelper extends FacebookSignedRequestFromInputHelper 33 | { 34 | 35 | /** 36 | * Returns the app data value. 37 | * 38 | * @return mixed|null 39 | */ 40 | public function getAppData() 41 | { 42 | return $this->signedRequest ? $this->signedRequest->get('app_data') : null; 43 | } 44 | 45 | /** 46 | * Get raw signed request from POST. 47 | * 48 | * @return string|null 49 | */ 50 | public function getRawSignedRequest() 51 | { 52 | $rawSignedRequest = $this->getRawSignedRequestFromPost(); 53 | if ($rawSignedRequest) { 54 | return $rawSignedRequest; 55 | } 56 | 57 | return null; 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphPage.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class GraphPage extends GraphObject 32 | { 33 | 34 | /** 35 | * Returns the ID for the user's page as a string if present. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns the Category for the user's page as a string if present. 46 | * 47 | * @return string|null 48 | */ 49 | public function getCategory() 50 | { 51 | return $this->getProperty('category'); 52 | } 53 | 54 | /** 55 | * Returns the Name of the user's page as a string if present. 56 | * 57 | * @return string|null 58 | */ 59 | public function getName() 60 | { 61 | return $this->getProperty('name'); 62 | } 63 | 64 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookRedirectLoginHelper.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookRedirectLoginHelper for the Facebook SDK for PHP 3 | 4 | A helper class for getting a FacebookSession using the OAuth protocol. 5 | 6 | 7 | 8 | ## Facebook\FacebookRedirectLoginHelper {#overview} 9 | 10 | If your web app uses Facebook Login on the back-end, you'll need to redirect your visitors to a URL at Facebook to initiate a login request. Facebook then redirects the user to your apps callback URL, providing session data. This helper class will generate the login URL for you, and can process and validate the data from Facebook, returning a `FacebookSession` on success. 11 | 12 | This class can be extended, and the `storeState($state)` and `loadState()` methods overridden, to store the state check using another method besides the default `$_SESSION`. 13 | 14 | Usage: 15 | 16 | ~~~~ 17 | 18 | $helper = new FacebookRedirectLoginHelper($redirect_url, $appId = NULL, $appSecret = NULL); 19 | echo 'Login with Facebook'; 20 | 21 | ~~~~ 22 | 23 | Then, in your callback page (at the redirect url) when Facebook sends the user back: 24 | 25 | ~~~~ 26 | 27 | $helper = new FacebookRedirectLoginHelper($redirect_url); 28 | try { 29 | $session = $helper->getSessionFromRedirect(); 30 | } catch(FacebookRequestException $ex) { 31 | // When Facebook returns an error 32 | } catch(\Exception $ex) { 33 | // When validation fails or other local issues 34 | } 35 | if ($session) { 36 | // Logged in. 37 | } 38 | 39 | ~~~~ 40 | 41 | 42 | 43 | ## Instance Methods {#instance-methods} 44 | 45 | ### getLoginUrl {#getloginurl} 46 | `getLoginUrl()` 47 | Generates the URL to redirect a web visitor to Facebook to login to your app. 48 | ### getLogoutUrl {#getlogouturl} 49 | `getLogoutUrl($next_url)` 50 | Generates the URL to redirect a web visitor to Facebook to logout, with a url to redirect to after. 51 | ### getSessionFromRedirect {#getsessionfromredirect} 52 | `getSessionFromRedirect()` 53 | Processes the redirect data from Facebook, if present. Returns a `FacebookSession` or `null`. 54 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookResponse.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookResponse for the Facebook SDK for PHP 3 | 4 | Represents a response from the Graph API. 5 | 6 | 7 | 8 | ## Facebook\FacebookResponse {#overview} 9 | 10 | Usage: 11 | 12 | ~~~~ 13 | // A FacebookResponse is returned from an executed FacebookRequest 14 | try { 15 | $response = (new FacebookRequest($session, 'GET', '/me'))->execute(); 16 | // You can get the request back: 17 | $request = $response->getRequest(); 18 | // You can get the response as a GraphObject: 19 | $object = $response->getGraphObject(); 20 | // You can get the response as a subclass of GraphObject: 21 | $me = $response->getGraphObject(GraphUser::className()); 22 | // If this response has multiple pages, you can get a request for the next or previous pages: 23 | $nextPageRequest = $response->getRequestForNextPage(); 24 | $previousPageRequest = $response->getRequestForPreviousPage(); 25 | } catch (FacebookRequestException $ex) { 26 | echo $ex->getMessage(); 27 | } catch (\Exception $ex) { 28 | echo $ex->getMessage(); 29 | } 30 | 31 | // You can also chain the methods together: 32 | $me = (new FacebookRequest( 33 | $session, 'GET', '/me' 34 | ))->execute()->getGraphObject(GraphUser::className); 35 | echo $me->getName(); 36 | ~~~~ 37 | 38 | 39 | 40 | ## Instance Methods {#instance-methods} 41 | 42 | ### getGraphObject {#getgraphobject} 43 | `getGraphObject(string $type = 'Facebook\GraphObject')` 44 | Returns the result as a `GraphObject`. If specified, a strongly-typed subclass of `GraphObject` is returned. 45 | ### getGraphObjectList {#getgraphobjectlist} 46 | `getGraphObjectList(string $type = 'Facebook\GraphObject')` 47 | Returns an array of `GraphObject` returned by this request. If specified, a strongly-typed subclass of `GraphObject` is returned. 48 | ### getRequest {#getrequest} 49 | `getRequest()` 50 | Returns the `FacebookRequest` that produced this response. 51 | ### getRequestForNextPage {#getnextpage} 52 | `getRequestForNextPage()` 53 | If the response has paginated data, produces a `FacebookRequest` for the next pge of data. 54 | ### getRequestForPreviousPage {#getpreviouspage} 55 | `getRequestForPreviousPage()` 56 | If the response has paginated data, produces a `FacebookRequest` for the previous page of data. 57 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookHttpable.php: -------------------------------------------------------------------------------- 1 | 2 | # Facebook SDK for PHP 3 | 4 | The Facebook SDK for PHP provides developers with a modern, native library for accessing the Graph API and taking advantage of Facebook Login. Usually this means you're developing with PHP for a Facebook Canvas app, building your own website, or adding server-side functionality to an app that already uses the [Facebook SDK for JavaScript](/docs/reference/javascript/). 5 | 6 | Take a look through our guide, [Getting Started with the Facebook SDK for PHP](/docs/php/gettingstarted), and then check out some of the examples below. 7 | 8 | 9 | 10 | ## Examples {#examples} 11 | 12 | * [Retrieve a users profile](/docs/php/howto/profilewithgraphapi) 13 | * [Post a link to a users feed](/docs/php/howto/postwithgraphapi) 14 | * [Upload a photo to a users profile](/docs/php/howto/uploadphoto) 15 | 16 | 17 | 18 | 19 | ## API Reference - Facebook namespace {#reference} 20 | 21 | [Facebook\FacebookSession](/docs/php/FacebookSession) 22 | An access token backed session used when making requests against the Graph API. 23 | 24 | [Facebook\FacebookRequest](/docs/php/FacebookRequest) 25 | Makes requests against the Graph API. 26 | 27 | [Facebook\FacebookResponse](/docs/php/FacebookResponse) 28 | A successful response from the Graph API resulting from a FacebookRequest. 29 | 30 | [Facebook\FacebookRequestException](/docs/php/FacebookRequestException) 31 | An error returned by the Graph API during a FacebookRequest. Subclasses: FacebookClientException, FacebookServerException, FacebookAuthorizationException, FacebookPermissionException, FacebookThrottleException, FacebookOtherException. 32 | 33 | [Facebook\GraphObject](/docs/php/GraphObject) 34 | Represents an object returned by the Graph API. Subclasses: GraphUser, GraphLocation, GraphSessionInfo 35 | 36 | [Facebook\FacebookRedirectLoginHelper](/docs/php/FacebookRedirectLoginHelper) 37 | A helper class for getting a FacebookSession using the OAuth protocol. 38 | 39 | [Facebook\FacebookCanvasLoginHelper](/docs/php/FacebookCanvasLoginHelper) 40 | A helper class for getting a FacebookSession from Facebook Canvas. 41 | 42 | [Facebook\FacebookJavaScriptLoginHelper](/docs/php/FacebookJavaScriptLoginHelper) 43 | A helper class for getting a FacebookSession from the Facebook SDK for JavaScript. 44 | 45 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookTestHelper.php: -------------------------------------------------------------------------------- 1 | true, 42 | 'name' => 'Foo Phpunit User', 43 | 'locale' => 'en_US', 44 | 'permissions' => implode(',', static::$testUserPermissions), 45 | ); 46 | 47 | $request = new FacebookRequest(static::getAppSession(), 'POST', $testUserPath, $params); 48 | $response = $request->execute()->getGraphObject(); 49 | 50 | static::$testUserId = $response->getProperty('id'); 51 | static::$testUserAccessToken = $response->getProperty('access_token'); 52 | } 53 | 54 | public static function getAppSession() 55 | { 56 | return new FacebookSession(static::getAppToken()); 57 | } 58 | 59 | public static function getAppToken() 60 | { 61 | return FacebookTestCredentials::$appId . '|' . FacebookTestCredentials::$appSecret; 62 | } 63 | 64 | public static function deleteTestUser() 65 | { 66 | if (!static::$testUserId) { 67 | return; 68 | } 69 | $testUserPath = '/' . static::$testUserId; 70 | $request = new FacebookRequest(static::getAppSession(), 'DELETE', $testUserPath); 71 | $request->execute(); 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookRedirectLoginHelperTest.php: -------------------------------------------------------------------------------- 1 | disableSessionStatusCheck(); 19 | $loginUrl = $helper->getLoginUrl(); 20 | $state = $_SESSION['FBRLH_state']; 21 | $params = array( 22 | 'client_id' => FacebookTestCredentials::$appId, 23 | 'redirect_uri' => self::REDIRECT_URL, 24 | 'state' => $state, 25 | 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, 26 | 'scope' => implode(',', array()) 27 | ); 28 | $expectedUrl = 'https://www.facebook.com/v2.0/dialog/oauth?'; 29 | $this->assertTrue(strpos($loginUrl, $expectedUrl) !== false); 30 | foreach ($params as $key => $value) { 31 | $this->assertTrue( 32 | strpos($loginUrl, $key . '=' . urlencode($value)) !== false 33 | ); 34 | } 35 | } 36 | 37 | public function testLogoutURL() 38 | { 39 | $helper = new FacebookRedirectLoginHelper( 40 | self::REDIRECT_URL, 41 | FacebookTestCredentials::$appId, 42 | FacebookTestCredentials::$appSecret 43 | ); 44 | $helper->disableSessionStatusCheck(); 45 | $logoutUrl = $helper->getLogoutUrl( 46 | FacebookTestHelper::$testSession, self::REDIRECT_URL 47 | ); 48 | $params = array( 49 | 'next' => self::REDIRECT_URL, 50 | 'access_token' => FacebookTestHelper::$testSession->getToken() 51 | ); 52 | $expectedUrl = 'https://www.facebook.com/logout.php?'; 53 | $this->assertTrue(strpos($logoutUrl, $expectedUrl) !== false); 54 | foreach ($params as $key => $value) { 55 | $this->assertTrue( 56 | strpos($logoutUrl, $key . '=' . urlencode($value)) !== false 57 | ); 58 | } 59 | } 60 | 61 | public function testCSPRNG() 62 | { 63 | $helper = new FacebookRedirectLoginHelper( 64 | self::REDIRECT_URL, 65 | FacebookTestCredentials::$appId, 66 | FacebookTestCredentials::$appSecret 67 | ); 68 | $this->assertEquals(1, preg_match('/^([0-9a-f]+)$/', $helper->random(32))); 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookSignedRequestFromInputHelperTest.php: -------------------------------------------------------------------------------- 1 | helper = new FooSignedRequestHelper('123', 'foo_app_secret'); 21 | } 22 | 23 | public function testSignedRequestDataCanBeRetrievedFromGetData() 24 | { 25 | $_GET['signed_request'] = 'foo_signed_request'; 26 | 27 | $rawSignedRequest = $this->helper->getRawSignedRequestFromGet(); 28 | 29 | $this->assertEquals('foo_signed_request', $rawSignedRequest); 30 | } 31 | 32 | public function testSignedRequestDataCanBeRetrievedFromPostData() 33 | { 34 | $_POST['signed_request'] = 'foo_signed_request'; 35 | 36 | $rawSignedRequest = $this->helper->getRawSignedRequestFromPost(); 37 | 38 | $this->assertEquals('foo_signed_request', $rawSignedRequest); 39 | } 40 | 41 | public function testSignedRequestDataCanBeRetrievedFromCookieData() 42 | { 43 | $_COOKIE['fbsr_123'] = 'foo_signed_request'; 44 | 45 | $rawSignedRequest = $this->helper->getRawSignedRequestFromCookie(); 46 | 47 | $this->assertEquals('foo_signed_request', $rawSignedRequest); 48 | } 49 | 50 | public function testSessionWillBeNullWhenAUserHasNotYetAuthorizedTheApp() 51 | { 52 | $this->helper->instantiateSignedRequest($this->rawSignedRequestUnauthorized); 53 | $session = $this->helper->getSession(); 54 | 55 | $this->assertNull($session); 56 | } 57 | 58 | public function testAFacebookSessionCanBeInstantiatedWhenAUserHasAuthorizedTheApp() 59 | { 60 | $this->helper->instantiateSignedRequest($this->rawSignedRequestAuthorized); 61 | $session = $this->helper->getSession(); 62 | 63 | $this->assertInstanceOf('Facebook\FacebookSession', $session); 64 | $this->assertEquals('foo_token', $session->getToken()); 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookStream.php: -------------------------------------------------------------------------------- 1 | stream = stream_context_create($options); 53 | } 54 | 55 | /** 56 | * The response headers from the stream wrapper 57 | * 58 | * @return array|null 59 | */ 60 | public function getResponseHeaders() 61 | { 62 | return $this->responseHeaders; 63 | } 64 | 65 | /** 66 | * Send a stream wrapped request 67 | * 68 | * @param string $url 69 | * 70 | * @return mixed 71 | */ 72 | public function fileGetContents($url) 73 | { 74 | $rawResponse = file_get_contents($url, false, $this->stream); 75 | $this->responseHeaders = $http_response_header; 76 | return $rawResponse; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphUserPage.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class GraphUserPage extends GraphObject 32 | { 33 | 34 | /** 35 | * Returns the ID for the user's page as a string if present. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns the Category for the user's page as a string if present. 46 | * 47 | * @return string|null 48 | */ 49 | public function getCategory() 50 | { 51 | return $this->getProperty('category'); 52 | } 53 | 54 | /** 55 | * Returns the Name of the user's page as a string if present. 56 | * 57 | * @return string|null 58 | */ 59 | public function getName() 60 | { 61 | return $this->getProperty('name'); 62 | } 63 | 64 | /** 65 | * Returns the Access Token used to access the user's page as a string if present. 66 | * 67 | * @return string|null 68 | */ 69 | public function getAccessToken() 70 | { 71 | return $this->getProperty('access_token'); 72 | } 73 | 74 | /** 75 | * Returns the Permissions for the user's page as an array if present. 76 | * 77 | * @return array|null 78 | */ 79 | public function getPermissions() 80 | { 81 | return $this->getProperty('perms'); 82 | } 83 | 84 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookSessionTest.php: -------------------------------------------------------------------------------- 1 | assertEquals( 19 | FacebookTestHelper::getAppToken(), $session->getToken() 20 | ); 21 | } 22 | 23 | public function testGetSessionInfo() 24 | { 25 | $response = FacebookTestHelper::$testSession->getSessionInfo(); 26 | $this->assertTrue($response instanceof GraphSessionInfo); 27 | $this->assertNotNull($response->getAppId()); 28 | $this->assertTrue($response->isValid()); 29 | $scopes = $response->getPropertyAsArray('scopes'); 30 | $this->assertTrue(is_array($scopes)); 31 | $this->assertEquals(5, count($scopes)); 32 | } 33 | 34 | public function testExtendAccessToken() 35 | { 36 | $response = FacebookTestHelper::$testSession->getLongLivedSession(); 37 | $this->assertTrue($response instanceof FacebookSession); 38 | $info = $response->getSessionInfo(); 39 | $nextWeek = time() + (60 * 60 * 24 * 7); 40 | $this->assertTrue( 41 | $info->getProperty('expires_at') > $nextWeek 42 | ); 43 | } 44 | 45 | public function testSessionFromSignedRequest() 46 | { 47 | $signedRequest = m::mock('Facebook\Entities\SignedRequest'); 48 | $signedRequest 49 | ->shouldReceive('get') 50 | ->with('code') 51 | ->once() 52 | ->andReturn(null); 53 | $signedRequest 54 | ->shouldReceive('get') 55 | ->with('oauth_token') 56 | ->once() 57 | ->andReturn('foo_token'); 58 | $signedRequest 59 | ->shouldReceive('get') 60 | ->with('expires', 0) 61 | ->once() 62 | ->andReturn(time() + (60 * 60 * 24)); 63 | $signedRequest 64 | ->shouldReceive('getUserId') 65 | ->once() 66 | ->andReturn('123'); 67 | 68 | $session = FacebookSession::newSessionFromSignedRequest($signedRequest); 69 | $this->assertInstanceOf('Facebook\FacebookSession', $session); 70 | $this->assertEquals('foo_token', $session->getToken()); 71 | $this->assertEquals('123', $session->getUserId()); 72 | } 73 | 74 | public function testAppSessionValidates() 75 | { 76 | $session = FacebookSession::newAppSession(); 77 | try { 78 | $session->validate(); 79 | } catch (\Facebook\FacebookSDKException $ex) { 80 | $this->fail('Exception thrown validating app session.'); 81 | } 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/README.md: -------------------------------------------------------------------------------- 1 | Facebook SDK for PHP 2 | ==================== 3 | 4 | [![Latest Stable Version](http://img.shields.io/badge/Latest%20Stable-4.0.10-blue.svg)](https://packagist.org/packages/facebook/php-sdk-v4) 5 | 6 | 7 | This repository contains the open source PHP SDK that allows you to access Facebook 8 | Platform from your PHP app. 9 | 10 | 11 | Usage 12 | ----- 13 | 14 | This version of the Facebook SDK for PHP requires PHP 5.4 or greater. 15 | 16 | Minimal example: 17 | 18 | ```php 19 | use Facebook\FacebookSession; 20 | use Facebook\FacebookRequest; 21 | use Facebook\GraphUser; 22 | use Facebook\FacebookRequestException; 23 | 24 | FacebookSession::setDefaultApplication('YOUR_APP_ID','YOUR_APP_SECRET'); 25 | 26 | // Use one of the helper classes to get a FacebookSession object. 27 | // FacebookRedirectLoginHelper 28 | // FacebookCanvasLoginHelper 29 | // FacebookJavaScriptLoginHelper 30 | // or create a FacebookSession with a valid access token: 31 | $session = new FacebookSession('access-token-here'); 32 | 33 | // Get the GraphUser object for the current user: 34 | 35 | try { 36 | $me = (new FacebookRequest( 37 | $session, 'GET', '/me' 38 | ))->execute()->getGraphObject(GraphUser::className()); 39 | echo $me->getName(); 40 | } catch (FacebookRequestException $e) { 41 | // The Graph API returned an error 42 | } catch (\Exception $e) { 43 | // Some other error occurred 44 | } 45 | 46 | ``` 47 | 48 | Complete documentation, installation instructions, and examples are available at: 49 | [https://developers.facebook.com/docs/php](https://developers.facebook.com/docs/php) 50 | 51 | 52 | Tests 53 | ----- 54 | 55 | 1) [Composer](https://getcomposer.org/) is a prerequisite for running the tests. 56 | 57 | Install composer globally, then run `composer install` to install required files. 58 | 59 | 2) Create a test app on [Facebook Developers](https://developers.facebook.com), then 60 | create `tests/FacebookTestCredentials.php` from `tests/FacebookTestCredentials.php.dist` 61 | and edit it to add your credentials. 62 | 63 | 3) The tests can be executed by running this command from the root directory: 64 | 65 | ```bash 66 | ./vendor/bin/phpunit 67 | ``` 68 | 69 | 70 | Contributing 71 | ------------ 72 | 73 | For us to accept contributions you will have to first have signed the 74 | [Contributor License Agreement](https://developers.facebook.com/opensource/cla). 75 | 76 | When committing, keep all lines to less than 80 characters, and try to 77 | follow the existing style. 78 | 79 | Before creating a pull request, squash your commits into a single commit. 80 | 81 | Add the comments where needed, and provide ample explanation in the 82 | commit message. 83 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/autoload.php: -------------------------------------------------------------------------------- 1 | execute()->getGraphObjectList(); 19 | $this->assertTrue(is_array($response)); 20 | } 21 | 22 | public function testArrayProperties() 23 | { 24 | $backingData = array( 25 | 'id' => 42, 26 | 'friends' => array( 27 | 'data' => array( 28 | array( 29 | 'id' => 1, 30 | 'name' => 'David' 31 | ), 32 | array( 33 | 'id' => 2, 34 | 'name' => 'Fosco' 35 | ) 36 | ), 37 | 'paging' => array( 38 | 'next' => 'nexturl' 39 | ) 40 | ) 41 | ); 42 | $obj = new GraphObject($backingData); 43 | $friends = $obj->getPropertyAsArray('friends'); 44 | $this->assertEquals(2, count($friends)); 45 | $this->assertTrue($friends[0] instanceof GraphObject); 46 | $this->assertTrue($friends[1] instanceof GraphObject); 47 | $this->assertEquals('David', $friends[0]->getProperty('name')); 48 | $this->assertEquals('Fosco', $friends[1]->getProperty('name')); 49 | 50 | $backingData = array( 51 | 'id' => 42, 52 | 'friends' => array( 53 | array( 54 | 'id' => 1, 55 | 'name' => 'Ilya' 56 | ), 57 | array( 58 | 'id' => 2, 59 | 'name' => 'Kevin' 60 | ) 61 | ) 62 | ); 63 | $obj = new GraphObject($backingData); 64 | $friends = $obj->getPropertyAsArray('friends'); 65 | $this->assertEquals(2, count($friends)); 66 | $this->assertTrue($friends[0] instanceof GraphObject); 67 | $this->assertTrue($friends[1] instanceof GraphObject); 68 | $this->assertEquals('Ilya', $friends[0]->getProperty('name')); 69 | $this->assertEquals('Kevin', $friends[1]->getProperty('name')); 70 | 71 | } 72 | 73 | public function testAsList() 74 | { 75 | $backingData = array( 76 | 'data' => array( 77 | array( 78 | 'id' => 1, 79 | 'name' => 'David' 80 | ), 81 | array( 82 | 'id' => 2, 83 | 'name' => 'Fosco' 84 | ) 85 | ) 86 | ); 87 | $enc = json_encode($backingData); 88 | $response = new FacebookResponse(null, json_decode($enc), $enc); 89 | $list = $response->getGraphObjectList(GraphUser::className()); 90 | $this->assertEquals(2, count($list)); 91 | $this->assertTrue($list[0] instanceof GraphObject); 92 | $this->assertTrue($list[1] instanceof GraphObject); 93 | $this->assertEquals('David', $list[0]->getName()); 94 | $this->assertEquals('Fosco', $list[1]->getName()); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphLocation.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphLocation extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the street component of the location 37 | * 38 | * @return string|null 39 | */ 40 | public function getStreet() 41 | { 42 | return $this->getProperty('street'); 43 | } 44 | 45 | /** 46 | * Returns the city component of the location 47 | * 48 | * @return string|null 49 | */ 50 | public function getCity() 51 | { 52 | return $this->getProperty('city'); 53 | } 54 | 55 | /** 56 | * Returns the state component of the location 57 | * 58 | * @return string|null 59 | */ 60 | public function getState() 61 | { 62 | return $this->getProperty('state'); 63 | } 64 | 65 | /** 66 | * Returns the country component of the location 67 | * 68 | * @return string|null 69 | */ 70 | public function getCountry() 71 | { 72 | return $this->getProperty('country'); 73 | } 74 | 75 | /** 76 | * Returns the zipcode component of the location 77 | * 78 | * @return string|null 79 | */ 80 | public function getZip() 81 | { 82 | return $this->getProperty('zip'); 83 | } 84 | 85 | /** 86 | * Returns the latitude component of the location 87 | * 88 | * @return float|null 89 | */ 90 | public function getLatitude() 91 | { 92 | return $this->getProperty('latitude'); 93 | } 94 | 95 | /** 96 | * Returns the street component of the location 97 | * 98 | * @return float|null 99 | */ 100 | public function getLongitude() 101 | { 102 | return $this->getProperty('longitude'); 103 | } 104 | 105 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookPageTabHelper.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | class FacebookPageTabHelper extends FacebookCanvasLoginHelper 32 | { 33 | 34 | /** 35 | * @var array|null 36 | */ 37 | protected $pageData; 38 | 39 | /** 40 | * Initialize the helper and process available signed request data. 41 | * 42 | * @param string|null $appId 43 | * @param string|null $appSecret 44 | */ 45 | public function __construct($appId = null, $appSecret = null) 46 | { 47 | parent::__construct($appId, $appSecret); 48 | 49 | if (!$this->signedRequest) { 50 | return; 51 | } 52 | 53 | $this->pageData = $this->signedRequest->get('page'); 54 | } 55 | 56 | /** 57 | * Returns a value from the page data. 58 | * 59 | * @param string $key 60 | * @param mixed|null $default 61 | * 62 | * @return mixed|null 63 | */ 64 | public function getPageData($key, $default = null) 65 | { 66 | if (isset($this->pageData[$key])) { 67 | return $this->pageData[$key]; 68 | } 69 | return $default; 70 | } 71 | 72 | /** 73 | * Returns true if the page is liked by the user. 74 | * 75 | * @return boolean 76 | */ 77 | public function isLiked() 78 | { 79 | return $this->getPageData('liked') === true; 80 | } 81 | 82 | /** 83 | * Returns true if the user is an admin. 84 | * 85 | * @return boolean 86 | */ 87 | public function isAdmin() 88 | { 89 | return $this->getPageData('admin') === true; 90 | } 91 | 92 | /** 93 | * Returns the page id if available. 94 | * 95 | * @return string|null 96 | */ 97 | public function getPageId() 98 | { 99 | return $this->getPageData('id'); 100 | } 101 | 102 | } 103 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/HttpClients/FacebookGuzzleHttpClientTest.php: -------------------------------------------------------------------------------- 1 | guzzleMock = m::mock('GuzzleHttp\Client'); 17 | $this->guzzleClient = new FacebookGuzzleHttpClient($this->guzzleMock); 18 | } 19 | 20 | public function tearDown() 21 | { 22 | m::close(); 23 | (new FacebookGuzzleHttpClient()); // Resets the static dependency injection 24 | } 25 | 26 | public function testCanSendNormalRequest() 27 | { 28 | $requestMock = m::mock('GuzzleHttp\Message\RequestInterface'); 29 | $requestMock 30 | ->shouldReceive('setHeader') 31 | ->once() 32 | ->with('X-foo', 'bar') 33 | ->andReturn(null); 34 | 35 | $responseMock = m::mock('GuzzleHttp\Message\ResponseInterface'); 36 | $responseMock 37 | ->shouldReceive('getStatusCode') 38 | ->once() 39 | ->andReturn(200); 40 | $responseMock 41 | ->shouldReceive('getHeaders') 42 | ->once() 43 | ->andReturn($this->fakeHeadersAsArray); 44 | $responseMock 45 | ->shouldReceive('getBody') 46 | ->once() 47 | ->andReturn($this->fakeRawBody); 48 | 49 | $this->guzzleMock 50 | ->shouldReceive('createRequest') 51 | ->once() 52 | ->with('GET', 'http://foo.com/', array()) 53 | ->andReturn($requestMock); 54 | $this->guzzleMock 55 | ->shouldReceive('send') 56 | ->once() 57 | ->with($requestMock) 58 | ->andReturn($responseMock); 59 | 60 | $this->guzzleClient->addRequestHeader('X-foo', 'bar'); 61 | $responseBody = $this->guzzleClient->send('http://foo.com/'); 62 | 63 | $this->assertEquals($responseBody, $this->fakeRawBody); 64 | $this->assertEquals($this->guzzleClient->getResponseHeaders(), $this->fakeHeadersAsArray); 65 | $this->assertEquals(200, $this->guzzleClient->getResponseHttpStatusCode()); 66 | } 67 | 68 | /** 69 | * @expectedException \Facebook\FacebookSDKException 70 | */ 71 | public function testThrowsExceptionOnClientError() 72 | { 73 | $requestMock = m::mock('GuzzleHttp\Message\RequestInterface'); 74 | $exceptionMock = m::mock( 75 | 'GuzzleHttp\Exception\RequestException', 76 | array( 77 | 'Foo Error', 78 | $requestMock, 79 | null, 80 | m::mock('GuzzleHttp\Exception\AdapterException'), 81 | )); 82 | 83 | $this->guzzleMock 84 | ->shouldReceive('createRequest') 85 | ->once() 86 | ->with('GET', 'http://foo.com/', array()) 87 | ->andReturn($requestMock); 88 | $this->guzzleMock 89 | ->shouldReceive('send') 90 | ->once() 91 | ->with($requestMock) 92 | ->andThrow($exceptionMock); 93 | 94 | $this->guzzleClient->send('http://foo.com/'); 95 | } 96 | 97 | } 98 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphSessionInfo.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphSessionInfo extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the application id the token was issued for. 37 | * 38 | * @return string|null 39 | */ 40 | public function getAppId() 41 | { 42 | return $this->getProperty('app_id'); 43 | } 44 | 45 | /** 46 | * Returns the application name the token was issued for. 47 | * 48 | * @return string|null 49 | */ 50 | public function getApplication() 51 | { 52 | return $this->getProperty('application'); 53 | } 54 | 55 | /** 56 | * Returns the date & time that the token expires. 57 | * 58 | * @return \DateTime|null 59 | */ 60 | public function getExpiresAt() 61 | { 62 | $stamp = $this->getProperty('expires_at'); 63 | if ($stamp) { 64 | return (new \DateTime())->setTimestamp($stamp); 65 | } else { 66 | return null; 67 | } 68 | } 69 | 70 | /** 71 | * Returns whether the token is valid. 72 | * 73 | * @return boolean 74 | */ 75 | public function isValid() 76 | { 77 | return $this->getProperty('is_valid'); 78 | } 79 | 80 | /** 81 | * Returns the date & time the token was issued at. 82 | * 83 | * @return \DateTime|null 84 | */ 85 | public function getIssuedAt() 86 | { 87 | $stamp = $this->getProperty('issued_at'); 88 | if ($stamp) { 89 | return (new \DateTime())->setTimestamp($stamp); 90 | } else { 91 | return null; 92 | } 93 | } 94 | 95 | /** 96 | * Returns the scope permissions associated with the token. 97 | * 98 | * @return array 99 | */ 100 | public function getScopes() 101 | { 102 | return $this->getPropertyAsArray('scopes'); 103 | } 104 | 105 | /** 106 | * Returns the login id of the user associated with the token. 107 | * 108 | * @return string|null 109 | */ 110 | public function getId() 111 | { 112 | return $this->getProperty('user_id'); 113 | } 114 | 115 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookCurl.php: -------------------------------------------------------------------------------- 1 | curl = curl_init(); 46 | } 47 | 48 | /** 49 | * Set a curl option 50 | * 51 | * @param $key 52 | * @param $value 53 | */ 54 | public function setopt($key, $value) 55 | { 56 | curl_setopt($this->curl, $key, $value); 57 | } 58 | 59 | /** 60 | * Set an array of options to a curl resource 61 | * 62 | * @param array $options 63 | */ 64 | public function setopt_array(array $options) 65 | { 66 | curl_setopt_array($this->curl, $options); 67 | } 68 | 69 | /** 70 | * Send a curl request 71 | * 72 | * @return mixed 73 | */ 74 | public function exec() 75 | { 76 | return curl_exec($this->curl); 77 | } 78 | 79 | /** 80 | * Return the curl error number 81 | * 82 | * @return int 83 | */ 84 | public function errno() 85 | { 86 | return curl_errno($this->curl); 87 | } 88 | 89 | /** 90 | * Return the curl error message 91 | * 92 | * @return string 93 | */ 94 | public function error() 95 | { 96 | return curl_error($this->curl); 97 | } 98 | 99 | /** 100 | * Get info from a curl reference 101 | * 102 | * @param $type 103 | * 104 | * @return mixed 105 | */ 106 | public function getinfo($type) 107 | { 108 | return curl_getinfo($this->curl, $type); 109 | } 110 | 111 | /** 112 | * Get the currently installed curl version 113 | * 114 | * @return array 115 | */ 116 | public function version() 117 | { 118 | return curl_version(); 119 | } 120 | 121 | /** 122 | * Close the resource connection to curl 123 | */ 124 | public function close() 125 | { 126 | curl_close($this->curl); 127 | } 128 | 129 | } 130 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphUser.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphUser extends GraphObject 33 | { 34 | 35 | /** 36 | * Returns the ID for the user as a string if present. 37 | * 38 | * @return string|null 39 | */ 40 | public function getId() 41 | { 42 | return $this->getProperty('id'); 43 | } 44 | 45 | /** 46 | * Returns the name for the user as a string if present. 47 | * 48 | * @return string|null 49 | */ 50 | public function getName() 51 | { 52 | return $this->getProperty('name'); 53 | } 54 | 55 | /** 56 | * Returns the first name for the user as a string if present. 57 | * 58 | * @return string|null 59 | */ 60 | public function getFirstName() 61 | { 62 | return $this->getProperty('first_name'); 63 | } 64 | 65 | /** 66 | * Returns the middle name for the user as a string if present. 67 | * 68 | * @return string|null 69 | */ 70 | public function getMiddleName() 71 | { 72 | return $this->getProperty('middle_name'); 73 | } 74 | 75 | /** 76 | * Returns the last name for the user as a string if present. 77 | * 78 | * @return string|null 79 | */ 80 | public function getLastName() 81 | { 82 | return $this->getProperty('last_name'); 83 | } 84 | 85 | /** 86 | * Returns the Facebook URL for the user as a string if available. 87 | * 88 | * @return string|null 89 | */ 90 | public function getLink() 91 | { 92 | return $this->getProperty('link'); 93 | } 94 | 95 | /** 96 | * Returns the users birthday, if available. 97 | * 98 | * @return \DateTime|null 99 | */ 100 | public function getBirthday() 101 | { 102 | $value = $this->getProperty('birthday'); 103 | if ($value) { 104 | return new \DateTime($value); 105 | } 106 | return null; 107 | } 108 | 109 | /** 110 | * Returns the current location of the user as a FacebookGraphLocation 111 | * if available. 112 | * 113 | * @return GraphLocation|null 114 | */ 115 | public function getLocation() 116 | { 117 | return $this->getProperty('location', GraphLocation::className()); 118 | } 119 | 120 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/HttpClients/FacebookStreamHttpClientTest.php: -------------------------------------------------------------------------------- 1 | streamMock = m::mock('Facebook\HttpClients\FacebookStream'); 17 | $this->streamClient = new FacebookStreamHttpClient($this->streamMock); 18 | } 19 | 20 | public function tearDown() 21 | { 22 | m::close(); 23 | (new FacebookStreamHttpClient()); // Resets the static dependency injection 24 | } 25 | 26 | public function testCanCompileHeader() 27 | { 28 | $this->streamClient->addRequestHeader('X-foo', 'bar'); 29 | $this->streamClient->addRequestHeader('X-bar', 'faz'); 30 | $header = $this->streamClient->compileHeader(); 31 | $this->assertEquals("X-foo: bar\r\nX-bar: faz", $header); 32 | } 33 | 34 | public function testCanFormatHeadersToArray() 35 | { 36 | $raw_header_array = explode("\n", trim($this->fakeRawHeader)); 37 | $header_array = FacebookStreamHttpClient::formatHeadersToArray($raw_header_array); 38 | $this->assertEquals($this->fakeHeadersAsArray, $header_array); 39 | } 40 | 41 | public function testCanGetHttpStatusCodeFromResponseHeader() 42 | { 43 | $http_code = FacebookStreamHttpClient::getStatusCodeFromHeader('HTTP/1.1 123 Foo Response'); 44 | $this->assertEquals('123', $http_code); 45 | } 46 | 47 | public function testCanSendNormalRequest() 48 | { 49 | $this->streamMock 50 | ->shouldReceive('streamContextCreate') 51 | ->once() 52 | ->with(\Mockery::on(function($arg) { 53 | if (!isset($arg['http']) || !isset($arg['ssl'])) { 54 | return false; 55 | } 56 | 57 | if ($arg['http'] !== array( 58 | 'method' => 'GET', 59 | 'timeout' => 60, 60 | 'ignore_errors' => true, 61 | 'header' => 'X-foo: bar', 62 | )) { 63 | return false; 64 | } 65 | 66 | if ($arg['ssl']['verify_peer'] !== true) { 67 | return false; 68 | } 69 | 70 | if (false === preg_match('/.fb_ca_chain_bundle\.crt$/', $arg['ssl']['cafile'])) { 71 | return false; 72 | } 73 | 74 | return true; 75 | })) 76 | ->andReturn(null); 77 | $this->streamMock 78 | ->shouldReceive('getResponseHeaders') 79 | ->once() 80 | ->andReturn(explode("\n", trim($this->fakeRawHeader))); 81 | $this->streamMock 82 | ->shouldReceive('fileGetContents') 83 | ->once() 84 | ->with('http://foo.com/') 85 | ->andReturn($this->fakeRawBody); 86 | 87 | $this->streamClient->addRequestHeader('X-foo', 'bar'); 88 | $responseBody = $this->streamClient->send('http://foo.com/'); 89 | 90 | $this->assertEquals($responseBody, $this->fakeRawBody); 91 | $this->assertEquals($this->streamClient->getResponseHeaders(), $this->fakeHeadersAsArray); 92 | $this->assertEquals(200, $this->streamClient->getResponseHttpStatusCode()); 93 | } 94 | 95 | /** 96 | * @expectedException \Facebook\FacebookSDKException 97 | */ 98 | public function testThrowsExceptionOnClientError() 99 | { 100 | $this->streamMock 101 | ->shouldReceive('streamContextCreate') 102 | ->once() 103 | ->andReturn(null); 104 | $this->streamMock 105 | ->shouldReceive('getResponseHeaders') 106 | ->once() 107 | ->andReturn(null); 108 | $this->streamMock 109 | ->shouldReceive('fileGetContents') 110 | ->once() 111 | ->with('http://foo.com/') 112 | ->andReturn(false); 113 | 114 | $this->streamClient->send('http://foo.com/'); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/FacebookSession.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # FacebookSession for the Facebook SDK for PHP 3 | 4 | Represents a Facebook Session, which is used when making requests to the Graph API. 5 | 6 | 7 | 8 | ## Facebook\FacebookSession {#overview} 9 | 10 | Usage: 11 | 12 | ~~~~ 13 | use Facebook\FacebookSession; 14 | 15 | FacebookSession::setDefaultApplication('app-id', 'app-secret'); 16 | 17 | // If you already have a valid access token: 18 | $session = new FacebookSession('access-token'); 19 | 20 | // If you're making app-level requests: 21 | $session = FacebookSession::newAppSession(); 22 | 23 | // To validate the session: 24 | try { 25 | $session->validate(); 26 | } catch (FacebookRequestException $ex) { 27 | // Session not valid, Graph API returned an exception with the reason. 28 | echo $ex->getMessage(); 29 | } catch (\Exception $ex) { 30 | // Graph API returned info, but it may mismatch the current app or have expired. 31 | echo $ex->getMessage(); 32 | } 33 | ~~~~ 34 | 35 | 36 | 37 | ## Static Methods {#static-methods} 38 | 39 | ### setDefaultApplication {#setdefaultapp} 40 | `setDefaultApplication(string $appId, string $appSecret)` 41 | Configures and app ID and secret that will be used by default throughout the SDK (but can be overridden whenever necessary using parameters to other methods. 42 | ### validate {#validate} 43 | `validate(Facebook\GraphSessionInfo $sessionInfo, string $appId = NULL, string $appSecret = NULL)` 44 | Ensures that the provided GraphSessionInfo is valid, throwing an exception if not. It does this by ensuring the app ID in the token info matches the given (or default) app ID, ensuring the token itself is valid, and ensuring that the expiration time has not passed. 45 | ### newAppSession {#newappsession} 46 | `newAppSession(string $appId = NULL, string $appSecret = NULL)` 47 | Returns a `Facebook\FacebookSession` configured with a token for the app which can be used for publishing and for requesting app-level information. 48 | ### newSessionFromSignedRequest {#newsessionfromsr} 49 | `newSessionFromSignedRequest(string $signedRequest)` 50 | Returns a `Facebook\FacebookSession` for the given signed request. 51 | 52 | 53 | 54 | ## Instance Methods {#instance-methods} 55 | 56 | ### getToken {#gettoken} 57 | `getToken()` 58 | Returns the token string for the session. 59 | ### getSessionInfo {#getsessioninfo} 60 | `getSessionInfo(string $appId = NULL, string $appSecret = NULL)` 61 | Equivalent to calling the /debug_token endpoint of the Graph API to get the details for the access token for this session. Returns a `Facebook\GraphSessionInfo` object. 62 | ### getLongLivedSession {#getlonglivedsession} 63 | `getLongLivedSession(string $appId = NULL, string $appSecret = NULL)` 64 | Returns a new `Facebook\FacebookSession` resulting from extending a short-lived access token. This method will make a network request. If you know you already have a long-lived session, you do not need to call this. The only time you get a short-lived session as of March 2014 is from the Facebook SDK for JavaScript. If this session is not short-lived, this method will return `$this`. A long-lived session is on the order of months. A short-lived session is on the order of hours. You can figure out whether a session is short-lived or long-lived by checking the expiration date in the session info, but it's not a precise thing. 65 | ### getExchangeToken {#getexchangetoken} 66 | `getExchangeToken(string $appId = NULL, string $appSecret = NULL)` 67 | Returns an exchange token string which can be sent back to clients and exchanged for a device-linked access token. You need this when your user did not log in on a particular device, but you want to be able to make Graph API calls from that device as this user. 68 | ### validate {#validatei} 69 | `validate(string $appId = NULL, string $appSecret = NULL)` 70 | Ensures that a session is valid, throwing an exception if not. It does this by fetching the token info, ensuring the app ID in the token info matches the given (or default) app ID, ensuring the token itself is valid, and ensuring that the expiration time has not passed. 71 | -------------------------------------------------------------------------------- /FacebookAutoPilot.php: -------------------------------------------------------------------------------- 1 | getSessionFromRedirect(); 16 | } 17 | catch(FacebookRequestException $ex) { 18 | die("FacebookRequestException: " . $ex->getMessage()); 19 | } 20 | catch(\Exception $ex) { 21 | die("Exception: " . $ex->getMessage()); 22 | } 23 | 24 | 25 | // if I'm logged in and ready to post on group pages 26 | if ($session) { 27 | 28 | $groups = (new FacebookRequest( 29 | $session, 30 | 'GET', 31 | '/me/groups' 32 | ))->execute()->getGraphObject()->asArray(); 33 | $_SESSION["groups"] = $groups["data"]; 34 | 35 | echo "Total Groups: " . count($groups["data"]); 36 | 37 | if(isset($_SESSION["groups"])) { 38 | echo '
Hi, you are logged into Facebook [ Log Out ] '; 39 | 40 | writeToLogs("\n\n\nPosting to Facebook Walls [" . date("Y-m-d h:i:sa", time()) . "]"); 41 | writeToLogs("\n----------------------------------------"); 42 | 43 | for($i = 0; $i < $maxGroups; $i++) { 44 | 45 | if($_SESSION["groups"][$i]) { 46 | $group = $_SESSION["groups"][$i]; 47 | 48 | // exclude certain groups 49 | $continue = true; 50 | if (strpos($group->name,'Science') !== false) { $continue = false; } 51 | else if (strpos($group->name,'UCC') !== false) { $continue = false; } 52 | else if(strpos($group->name,'Udemy') !== false) { $continue = false; } 53 | else if (strpos($group->name,'JCI') !== false) { $continue = false; } 54 | else if (strpos($group->name,'Cappamore') !== false) { $continue = false; } 55 | 56 | if($continue) { 57 | $postURL = '/' . $group->id . '/feed'; 58 | 59 | $message = array( 60 | 'message' => 'Hey guys! 61 | 62 | Thought I’d give something back to the community :) 63 | 64 | Check out v2 of AppLandr, which allows you to generate beautifully crafted (free or paid) landing pages for your mobile applications! And of course it’s on Product Hunt! 65 | 66 | Would love to hear your thoughts! 67 | 68 | http://applandr.com', 69 | 'link' => 'http://applandr.com', 70 | 'picture' => 'http://www.applandr.com/lib/images/dark.png' 71 | ); 72 | 73 | $groupUrl = "http://www.facebook.com/groups/" . $group->id; 74 | 75 | try { 76 | $postRequest = new FacebookRequest($session, 'POST', $postURL, $message); 77 | $postRequest->execute(); 78 | 79 | $logMessage = "\nSUCCESS: posting message to $groupUrl"; 80 | writeToLogs($logMessage); 81 | echo "
SUCCESS: posting message to " . $group->name . ""; 82 | } 83 | catch(FacebookRequestException $ex) { 84 | $logMessage = "\nFAIL: posting message to " . $groupUrl . " with ERROR: " . $e->getMessage(); 85 | writeToLogs($logMessage); 86 | echo "
FAIL: posting message to " . $group->name . " with ERROR: " . $e->getMessage(); 87 | } 88 | 89 | $delayTime = rand($minDelayTime, $maxDelayTime); 90 | sleep($delayTime); 91 | } 92 | } 93 | } 94 | } 95 | } else { 96 | $loginURL = $helper->getLoginUrl( array( 'scope' => $requiredPermissions ) ); 97 | echo 'Login with Facebook'; 98 | } 99 | 100 | 101 | if(isset($_GET["logOut"]) && $_GET["logOut"]==1){ 102 | unset($_SESSION["groups"]); 103 | header("location: ". $redirectURL); 104 | } 105 | 106 | 107 | function writeToLogs($textToWrite) { 108 | $currentfile = "logs.txt"; 109 | $updatedFile = file_get_contents($currentfile); 110 | $updatedFile .= $textToWrite; 111 | file_put_contents($currentfile, $updatedFile); 112 | } 113 | ?> -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookGuzzleHttpClient.php: -------------------------------------------------------------------------------- 1 | requestHeaders[$key] = $value; 71 | } 72 | 73 | /** 74 | * The headers returned in the response 75 | * 76 | * @return array 77 | */ 78 | public function getResponseHeaders() 79 | { 80 | return $this->responseHeaders; 81 | } 82 | 83 | /** 84 | * The HTTP status response code 85 | * 86 | * @return int 87 | */ 88 | public function getResponseHttpStatusCode() 89 | { 90 | return $this->responseHttpStatusCode; 91 | } 92 | 93 | /** 94 | * Sends a request to the server 95 | * 96 | * @param string $url The endpoint to send the request to 97 | * @param string $method The request method 98 | * @param array $parameters The key value pairs to be sent in the body 99 | * 100 | * @return string Raw response from the server 101 | * 102 | * @throws \Facebook\FacebookSDKException 103 | */ 104 | public function send($url, $method = 'GET', $parameters = array()) 105 | { 106 | $options = array(); 107 | if ($parameters) { 108 | $options = array('body' => $parameters); 109 | } 110 | 111 | $request = self::$guzzleClient->createRequest($method, $url, $options); 112 | 113 | foreach($this->requestHeaders as $k => $v) { 114 | $request->setHeader($k, $v); 115 | } 116 | 117 | try { 118 | $rawResponse = self::$guzzleClient->send($request); 119 | } catch (RequestException $e) { 120 | if ($e->getPrevious() instanceof AdapterException) { 121 | throw new FacebookSDKException($e->getMessage(), $e->getCode()); 122 | } 123 | $rawResponse = $e->getResponse(); 124 | } 125 | 126 | $this->responseHttpStatusCode = $rawResponse->getStatusCode(); 127 | $this->responseHeaders = $rawResponse->getHeaders(); 128 | 129 | return $rawResponse->getBody(); 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/FacebookRequestTest.php: -------------------------------------------------------------------------------- 1 | execute()->getGraphObject(); 17 | $this->assertNotNull($response->getProperty('id')); 18 | $this->assertNotNull($response->getProperty('name')); 19 | } 20 | 21 | public function testCanPostAndDelete() 22 | { 23 | // Create a test user 24 | $params = array( 25 | 'name' => 'Foo User', 26 | ); 27 | $response = ( 28 | new FacebookRequest( 29 | new FacebookSession(FacebookTestHelper::getAppToken()), 30 | 'POST', 31 | '/' . FacebookTestCredentials::$appId . '/accounts/test-users', 32 | $params 33 | ))->execute()->getGraphObject(); 34 | $user_id = $response->getProperty('id'); 35 | $this->assertNotNull($user_id); 36 | 37 | // Delete test user 38 | $response = ( 39 | new FacebookRequest( 40 | new FacebookSession(FacebookTestHelper::getAppToken()), 41 | 'DELETE', 42 | '/' . $user_id 43 | ))->execute()->getGraphObject()->asArray(); 44 | $this->assertTrue($response); 45 | } 46 | 47 | public function testETagHit() 48 | { 49 | $response = ( 50 | new FacebookRequest( 51 | FacebookTestHelper::$testSession, 52 | 'GET', 53 | '/104048449631599' 54 | ))->execute(); 55 | 56 | $response = ( 57 | new FacebookRequest( 58 | FacebookTestHelper::$testSession, 59 | 'GET', 60 | '/104048449631599', 61 | null, 62 | null, 63 | $response->getETag() 64 | ))->execute(); 65 | 66 | $this->assertTrue($response->isETagHit()); 67 | $this->assertNull($response->getETag()); 68 | } 69 | 70 | public function testETagMiss() 71 | { 72 | $response = ( 73 | new FacebookRequest( 74 | FacebookTestHelper::$testSession, 75 | 'GET', 76 | '/104048449631599', 77 | null, 78 | null, 79 | 'someRandomValue' 80 | ))->execute(); 81 | 82 | $this->assertFalse($response->isETagHit()); 83 | $this->assertNotNull($response->getETag()); 84 | } 85 | 86 | public function testGracefullyHandlesUrlAppending() 87 | { 88 | $params = array(); 89 | $url = 'https://www.foo.com/'; 90 | $processed_url = FacebookRequest::appendParamsToUrl($url, $params); 91 | $this->assertEquals('https://www.foo.com/', $processed_url); 92 | 93 | $params = array( 94 | 'access_token' => 'foo', 95 | ); 96 | $url = 'https://www.foo.com/'; 97 | $processed_url = FacebookRequest::appendParamsToUrl($url, $params); 98 | $this->assertEquals('https://www.foo.com/?access_token=foo', $processed_url); 99 | 100 | $params = array( 101 | 'access_token' => 'foo', 102 | 'bar' => 'baz', 103 | ); 104 | $url = 'https://www.foo.com/?foo=bar'; 105 | $processed_url = FacebookRequest::appendParamsToUrl($url, $params); 106 | $this->assertEquals('https://www.foo.com/?access_token=foo&bar=baz&foo=bar', $processed_url); 107 | 108 | $params = array( 109 | 'access_token' => 'foo', 110 | ); 111 | $url = 'https://www.foo.com/?foo=bar&access_token=bar'; 112 | $processed_url = FacebookRequest::appendParamsToUrl($url, $params); 113 | $this->assertEquals('https://www.foo.com/?access_token=bar&foo=bar', $processed_url); 114 | } 115 | 116 | public function testAppSecretProof() 117 | { 118 | $enableAppSecretProof = FacebookSession::useAppSecretProof(); 119 | 120 | FacebookSession::enableAppSecretProof(true); 121 | $request = new FacebookRequest( 122 | FacebookTestHelper::$testSession, 123 | 'GET', 124 | '/me' 125 | ); 126 | $this->assertTrue(isset($request->getParameters()['appsecret_proof'])); 127 | 128 | 129 | FacebookSession::enableAppSecretProof(false); 130 | $request = new FacebookRequest( 131 | FacebookTestHelper::$testSession, 132 | 'GET', 133 | '/me' 134 | ); 135 | $this->assertFalse(isset($request->getParameters()['appsecret_proof'])); 136 | 137 | FacebookSession::enableAppSecretProof($enableAppSecretProof); 138 | } 139 | 140 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookSignedRequestFromInputHelper.php: -------------------------------------------------------------------------------- 1 | appId = FacebookSession::_getTargetAppId($appId); 64 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); 65 | 66 | $this->instantiateSignedRequest(); 67 | } 68 | 69 | /** 70 | * Instantiates a new SignedRequest entity. 71 | * 72 | * @param string|null 73 | */ 74 | public function instantiateSignedRequest($rawSignedRequest = null) 75 | { 76 | $rawSignedRequest = $rawSignedRequest ?: $this->getRawSignedRequest(); 77 | 78 | if (!$rawSignedRequest) { 79 | return; 80 | } 81 | 82 | $this->signedRequest = new SignedRequest($rawSignedRequest, $this->state, $this->appSecret); 83 | } 84 | 85 | /** 86 | * Instantiates a FacebookSession from the signed request from input. 87 | * 88 | * @return FacebookSession|null 89 | */ 90 | public function getSession() 91 | { 92 | if ($this->signedRequest && $this->signedRequest->hasOAuthData()) { 93 | return FacebookSession::newSessionFromSignedRequest($this->signedRequest); 94 | } 95 | return null; 96 | } 97 | 98 | /** 99 | * Returns the SignedRequest entity. 100 | * 101 | * @return \Facebook\Entities\SignedRequest|null 102 | */ 103 | public function getSignedRequest() 104 | { 105 | return $this->signedRequest; 106 | } 107 | 108 | /** 109 | * Returns the user_id if available. 110 | * 111 | * @return string|null 112 | */ 113 | public function getUserId() 114 | { 115 | return $this->signedRequest ? $this->signedRequest->getUserId() : null; 116 | } 117 | 118 | /** 119 | * Get raw signed request from input. 120 | * 121 | * @return string|null 122 | */ 123 | abstract public function getRawSignedRequest(); 124 | 125 | /** 126 | * Get raw signed request from GET input. 127 | * 128 | * @return string|null 129 | */ 130 | public function getRawSignedRequestFromGet() 131 | { 132 | if (isset($_GET['signed_request'])) { 133 | return $_GET['signed_request']; 134 | } 135 | 136 | return null; 137 | } 138 | 139 | /** 140 | * Get raw signed request from POST input. 141 | * 142 | * @return string|null 143 | */ 144 | public function getRawSignedRequestFromPost() 145 | { 146 | if (isset($_POST['signed_request'])) { 147 | return $_POST['signed_request']; 148 | } 149 | 150 | return null; 151 | } 152 | 153 | /** 154 | * Get raw signed request from cookie set from the Javascript SDK. 155 | * 156 | * @return string|null 157 | */ 158 | public function getRawSignedRequestFromCookie() 159 | { 160 | if (isset($_COOKIE['fbsr_' . $this->appId])) { 161 | return $_COOKIE['fbsr_' . $this->appId]; 162 | } 163 | return null; 164 | } 165 | 166 | } 167 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphAlbum.php: -------------------------------------------------------------------------------- 1 | 30 | */ 31 | 32 | class GraphAlbum extends GraphObject 33 | { 34 | /** 35 | * Returns the ID for the album. 36 | * 37 | * @return string|null 38 | */ 39 | public function getId() 40 | { 41 | return $this->getProperty('id'); 42 | } 43 | 44 | /** 45 | * Returns whether the viewer can upload photos to this album. 46 | * 47 | * @return boolean|null 48 | */ 49 | public function canUpload() 50 | { 51 | return $this->getProperty('can_upload'); 52 | } 53 | 54 | /** 55 | * Returns the number of photos in this album. 56 | * 57 | * @return int|null 58 | */ 59 | public function getCount() 60 | { 61 | return$this->getProperty('count'); 62 | } 63 | 64 | /** 65 | * Returns the ID of the album's cover photo. 66 | * 67 | * @return string|null 68 | */ 69 | public function getCoverPhoto() 70 | { 71 | return$this->getProperty('cover_photo'); 72 | } 73 | 74 | /** 75 | * Returns the time the album was initially created. 76 | * 77 | * @return \DateTime|null 78 | */ 79 | public function getCreatedTime() 80 | { 81 | $value = $this->getProperty('created_time'); 82 | if ($value) { 83 | return new \DateTime($value); 84 | } 85 | return null; 86 | } 87 | 88 | /** 89 | * Returns the time the album was updated. 90 | * 91 | * @return \DateTime|null 92 | */ 93 | public function getUpdatedTime() 94 | { 95 | $value = $this->getProperty('updated_time'); 96 | if ($value) { 97 | return new \DateTime($value); 98 | } 99 | return null; 100 | } 101 | 102 | /** 103 | * Returns the description of the album. 104 | * 105 | * @return string|null 106 | */ 107 | public function getDescription() 108 | { 109 | return$this->getProperty('description'); 110 | } 111 | 112 | /** 113 | * Returns profile that created the album. 114 | * 115 | * @return GraphUser|null 116 | */ 117 | public function getFrom() 118 | { 119 | return $this->getProperty('from', GraphUser::className()); 120 | } 121 | 122 | /** 123 | * Returns a link to this album on Facebook. 124 | * 125 | * @return string|null 126 | */ 127 | public function getLink() 128 | { 129 | return$this->getProperty('link'); 130 | } 131 | 132 | /** 133 | * Returns the textual location of the album. 134 | * 135 | * @return string|null 136 | */ 137 | public function getLocation() 138 | { 139 | return$this->getProperty('location'); 140 | } 141 | 142 | /** 143 | * Returns the title of the album. 144 | * 145 | * @return string|null 146 | */ 147 | public function getName() 148 | { 149 | return$this->getProperty('name'); 150 | } 151 | 152 | /** 153 | * Returns the privacy settings for the album. 154 | * 155 | * @return string|null 156 | */ 157 | public function getPrivacy() 158 | { 159 | return$this->getProperty('privacy'); 160 | } 161 | 162 | /** 163 | * Returns the type of the album. enum{profile, mobile, wall, normal, album} 164 | * 165 | * @return string|null 166 | */ 167 | public function getType() 168 | { 169 | return$this->getProperty('type'); 170 | } 171 | 172 | //TODO: public function getPlace() that should return GraphPage 173 | } 174 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/sdk_getting_started.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # Getting started with the Facebook SDK for PHP 3 | 4 | The Facebook SDK for PHP provides developers with a modern, native library for accessing the Graph API and taking advantage of Facebook Login. Usually this means you're developing with PHP for a Facebook Canvas app, building your own website, or adding server-side functionality to an app that already uses the [Facebook SDK for JavaScript](/docs/reference/javascript/). 5 | 6 | 7 | 8 | ## Download the SDK {#download} 9 | 10 | %FB(devsite:markdown-wiki:info-card { 11 | content: "The Facebook SDK for PHP v4 requires PHP 5.4 or greater.", 12 | type: 'warning', 13 | }) 14 | 15 | If you're using [Composer](https://getcomposer.org/) as a package manager for PHP, which we recommend, installing the SDK is as easy as adding a require entry for the Facebook SDK for PHP to the composer.json file in the root of your project: 16 | 17 | ~~~~ 18 | { 19 | "require" : { 20 | "facebook/php-sdk-v4" : "4.0.*" 21 | } 22 | } 23 | ~~~~ 24 | 25 | Then run composer with the install parameter, and it will download the newest version. If you're using the autoloader as part of Composer, the Facebook namespace will be available for use without adding require statements for all of the files. 26 | 27 | If you're not using Composer, you can download the SDK from our GitHub: 28 | 29 | %FB(devsite:markdown-wiki:button { 30 | text: 'Download the PHP SDK', 31 | href: 'https://github.com/facebook/facebook-php-sdk-v4/archive/4.0-dev.zip', 32 | size: 'large', 33 | use: 'special', 34 | }) 35 | 36 | 37 | 38 | ## Initializing {#init} 39 | 40 | You will need to have configured a Facebook App, which you can obtain from the [App Dashboard](http://developers.facebook.com/apps). 41 | 42 | Then, initialize the SDK with your app ID and secret: 43 | 44 | ~~~ 45 | FacebookSession::setDefaultApplication('YOUR_APP_ID', 'YOUR_APP_SECRET'); 46 | ~~~ 47 | 48 | 49 | 50 | ## Authentication and authorization {#authentication} 51 | 52 | The SDK can be used to support login your site using a Facebook account. On the server-side, the SDK provides helper classes for the most common scenarios. 53 | 54 | For most websites, you'll use the [FacebookRedirectLoginHelper](/docs/php/FacebookRedirectLoginHelper). Generate the login URL to redirect visitors to with the `getLoginUrl()` method, redirect them, and then process the response from Facebook with the `getSessionFromRedirect()` method, which returns a `FacebookSession`. 55 | 56 | ~~~~ 57 | $helper = new FacebookRedirectLoginHelper('your redirect URL here'); 58 | $loginUrl = $helper->getLoginUrl(); 59 | // Use the login url on a link or button to redirect to Facebook for authentication 60 | ~~~~ 61 | 62 | ~~~~ 63 | $helper = new FacebookRedirectLoginHelper(); 64 | try { 65 | $session = $helper->getSessionFromRedirect(); 66 | } catch(FacebookRequestException $ex) { 67 | // When Facebook returns an error 68 | } catch(\Exception $ex) { 69 | // When validation fails or other local issues 70 | } 71 | if ($session) { 72 | // Logged in 73 | } 74 | ~~~~ 75 | 76 | If your app is on Facebook Canvas, use the `getSession()` method on [FacebookCanvasLoginHelper](/docs/php/FacebookCanvasLoginHelper) to get a `FacebookSession` for the user. 77 | 78 | ~~~~ 79 | $helper = new FacebookCanvasLoginHelper(); 80 | try { 81 | $session = $helper->getSession(); 82 | } catch(FacebookRequestException $ex) { 83 | // When Facebook returns an error 84 | } catch(\Exception $ex) { 85 | // When validation fails or other local issues 86 | } 87 | if ($session) { 88 | // Logged in 89 | } 90 | ~~~~ 91 | 92 | If you're already using the Facebook SDK for JavaScript to authenticate users, you can also log them in on the server side with the [FacebookJavaScriptLoginHelper](/docs/php/FacebookJavaScriptLoginHelper). The `getSession()` method will return a `FacebookSession`. 93 | 94 | ~~~~ 95 | $helper = new FacebookJavaScriptLoginHelper(); 96 | try { 97 | $session = $helper->getSession(); 98 | } catch(FacebookRequestException $ex) { 99 | // When Facebook returns an error 100 | } catch(\Exception $ex) { 101 | // When validation fails or other local issues 102 | } 103 | if ($session) { 104 | // Logged in 105 | } 106 | ~~~~ 107 | 108 | You can also create a `FacebookSession` with an access token you've acquired through some other means, by passing it to the constructor. 109 | 110 | ~~~~ 111 | $session = new FacebookSession('access token here'); 112 | ~~~~ 113 | 114 | 115 | 116 | ## Making Requests to the Graph API {#making-requests} 117 | 118 | Once you have a `FacebookSession` you can begin making calls to the Graph API with [FacebookRequest](/docs/php/FacebookRequest). 119 | 120 | ~~~~ 121 | $request = new FacebookRequest($session, 'GET', '/me'); 122 | $response = $request->execute(); 123 | $graphObject = $response->getGraphObject(); 124 | ~~~~ 125 | 126 | You can also chain these methods: 127 | 128 | ~~~~ 129 | $me = (new FacebookRequest( 130 | $session, 'GET', '/me' 131 | ))->execute()->getGraphObject(GraphUser::className()); 132 | ~~~~ 133 | 134 | For more details, see the examples and API reference for all of these classes listed on the [landing page for the Facebook SDK for PHP](/docs/reference/php). 135 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/GraphObject.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class GraphObject 33 | { 34 | 35 | /** 36 | * @var array - Holds the raw associative data for this object 37 | */ 38 | protected $backingData; 39 | 40 | /** 41 | * Creates a GraphObject using the data provided. 42 | * 43 | * @param array $raw 44 | */ 45 | public function __construct($raw) 46 | { 47 | if ($raw instanceof \stdClass) { 48 | $raw = get_object_vars($raw); 49 | } 50 | $this->backingData = $raw; 51 | 52 | if (isset($this->backingData['data']) && count($this->backingData) === 1) { 53 | if ($this->backingData['data'] instanceof \stdClass) { 54 | $this->backingData = get_object_vars($this->backingData['data']); 55 | } else { 56 | $this->backingData = $this->backingData['data']; 57 | } 58 | } 59 | } 60 | 61 | /** 62 | * cast - Return a new instance of a FacebookGraphObject subclass for this 63 | * objects underlying data. 64 | * 65 | * @param string $type The GraphObject subclass to cast to 66 | * 67 | * @return GraphObject 68 | * 69 | * @throws FacebookSDKException 70 | */ 71 | public function cast($type) 72 | { 73 | if ($this instanceof $type) { 74 | return $this; 75 | } 76 | if (is_subclass_of($type, GraphObject::className())) { 77 | return new $type($this->backingData); 78 | } else { 79 | throw new FacebookSDKException( 80 | 'Cannot cast to an object that is not a GraphObject subclass', 620 81 | ); 82 | } 83 | } 84 | 85 | /** 86 | * asArray - Return a key-value associative array for the given graph object. 87 | * 88 | * @return array 89 | */ 90 | public function asArray() 91 | { 92 | return $this->backingData; 93 | } 94 | 95 | /** 96 | * getProperty - Gets the value of the named property for this graph object, 97 | * cast to the appropriate subclass type if provided. 98 | * 99 | * @param string $name The property to retrieve 100 | * @param string $type The subclass of GraphObject, optionally 101 | * 102 | * @return mixed 103 | */ 104 | public function getProperty($name, $type = 'Facebook\GraphObject') 105 | { 106 | if (isset($this->backingData[$name])) { 107 | $value = $this->backingData[$name]; 108 | if (is_scalar($value)) { 109 | return $value; 110 | } else { 111 | return (new GraphObject($value))->cast($type); 112 | } 113 | } else { 114 | return null; 115 | } 116 | } 117 | 118 | /** 119 | * getPropertyAsArray - Get the list value of a named property for this graph 120 | * object, where each item has been cast to the appropriate subclass type 121 | * if provided. 122 | * 123 | * Calling this for a property that is not an array, the behavior 124 | * is undefined, so don’t do this. 125 | * 126 | * @param string $name The property to retrieve 127 | * @param string $type The subclass of GraphObject, optionally 128 | * 129 | * @return array 130 | */ 131 | public function getPropertyAsArray($name, $type = 'Facebook\GraphObject') 132 | { 133 | $target = array(); 134 | if (isset($this->backingData[$name]['data'])) { 135 | $target = $this->backingData[$name]['data']; 136 | } else if (isset($this->backingData[$name]) 137 | && !is_scalar($this->backingData[$name])) { 138 | $target = $this->backingData[$name]; 139 | } 140 | $out = array(); 141 | foreach ($target as $key => $value) { 142 | if (is_scalar($value)) { 143 | $out[$key] = $value; 144 | } else { 145 | $out[$key] = (new GraphObject($value))->cast($type); 146 | } 147 | } 148 | return $out; 149 | } 150 | 151 | /** 152 | * getPropertyNames - Returns a list of all properties set on the object. 153 | * 154 | * @return array 155 | */ 156 | public function getPropertyNames() 157 | { 158 | return array_keys($this->backingData); 159 | } 160 | 161 | /** 162 | * Returns the string class name of the GraphObject or subclass. 163 | * 164 | * @return string 165 | */ 166 | public static function className() 167 | { 168 | return get_called_class(); 169 | } 170 | 171 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/docs/GraphObject.fbmd: -------------------------------------------------------------------------------- 1 | 2 | # GraphObject for the Facebook SDK for PHP 3 | 4 | Represents an object returned by the Graph API. 5 | 6 | 7 | 8 | 9 | ## Facebook\GraphObject {#overview} 10 | 11 | This base class has several subclasses, some are provided by default: 12 | 13 | [__GraphUser__](#user-instance-methods) 14 | [__GraphLocation__](#location-instance-methods) 15 | [__GraphSessionInfo__](#sessioninfo-instance-methods) 16 | 17 | Usage: 18 | 19 | ~~~~ 20 | // Get the base class GraphObject from the response 21 | $object = $response->getGraphObject(); 22 | 23 | // Get the response typed as a GraphUser 24 | $user = $response->getGraphObject(GraphUser::className()); 25 | // or convert the base object previously accessed 26 | // $user = $object->cast(GraphUser::className()); 27 | 28 | // Get the response typed as a GraphLocation 29 | $loc = $response->getGraphObject(GraphLocation::className()); 30 | // or convert the base object previously accessed 31 | // $loc = $object->cast(GraphLocation::className()); 32 | 33 | // User example 34 | echo $object->getProperty('name'); 35 | echo $user->getName(); 36 | 37 | // Location example 38 | echo $object->getProperty('country'); 39 | echo $loc->getCountry(); 40 | 41 | // SessionInfo example 42 | $info = $session->getSessionInfo()); 43 | echo $info->getxpiresAt(); 44 | ~~~~ 45 | 46 | 47 | 48 | 49 | ## GraphObject Instance Methods {#instance-methods} 50 | 51 | ### cast {#cast} 52 | `cast(string $type)` 53 | Returns a new instance of a GraphObject subclass with this objects underlying data. 54 | 55 | ### asArray {#asarray} 56 | `asArray()` 57 | Returns the raw representation (associative arrays, nested) of this objects underlying data. 58 | 59 | ### getProperty {#getproperty} 60 | `getProperty(string $name, string $type = 'Facebook\GraphObject')` 61 | Gets the value of a named key for this graph object. If the value is a scalar (string, number, etc.) it will be returned. If it's an associative array, it will be returned as a GraphObject cast to the appropriate subclass type if provided. 62 | 63 | ### getPropertyAsArray {#getproparray} 64 | `getPropertyAsArray()` 65 | Gets the contents of a named array property on this graph object. If the values are scalar (strings, numbers, etc.) they will be returned as-is. If the values are associative arrays, they will be returned as GraphObjects cast to the appropriate subclass type if provided. 66 | 67 | ### getPropertyNames 68 | `getPropertyNames()` 69 | Returns an array with the names of all properties present on this graph object. 70 | 71 | 72 | 73 | ## GraphUser Instance Methods {#user-instance-methods} 74 | 75 | ### getId {#getid} 76 | `getId()` 77 | Returns the `id` property for the user as a string if present. 78 | ### getName {#getname} 79 | `getName()` 80 | Returns the `name` property for the user as a string if present. 81 | ### getFirstName {#getfirstname} 82 | `getFirstName()` 83 | Returns the `first_name` property for the user as a string if present. 84 | ### getMiddleName {#getmiddlename} 85 | `getMiddleName()` 86 | Returns the `middle_name` property for the user as a string if present. 87 | ### getLastName {#getlastname} 88 | `getLastName()` 89 | Returns the `last_name` property for the user as a string if present. 90 | ### getLink {#getlink} 91 | `getLink()` 92 | Returns the `link` property for the user as a string if present. 93 | ### getUsername {#getusername} 94 | `getUsername()` 95 | Returns the `username` property for the user as a string if present. 96 | ### getBirthday {#getbirthday} 97 | `getBirthday()` 98 | Returns the `birthday` property for the user as a `\DateTime` if present. 99 | ### getLocation {#getlocation} 100 | `getLocation()` 101 | Returns the `location` property for the user as a `Facebook\GraphLocation` if present.' 102 | 103 | 104 | 105 | ## GraphLocation Instance Methods {#location-instance-methods} 106 | 107 | ### getStreet {#getstreet} 108 | `getStreet()` 109 | Returns the `street` property for the location as a string if present. 110 | ### getCity {#getcity} 111 | `getCity()` 112 | Returns the `city` property for the location as a string if present. 113 | ### getState {#getstate} 114 | `getState()` 115 | Returns the `state` property for the location as a string if present. 116 | ### getCountry {#getcountry} 117 | `getCountry()` 118 | Returns the `country` property for the location as a string if present. 119 | ### getZip {#getzip} 120 | `getZip()` 121 | Returns the `zip` property for the user as a location if present. 122 | ### getLatitude {#getlat} 123 | `getLatitude()` 124 | Returns the `latitude` property for the location as a float if present. 125 | ### getLongitude {#getlon} 126 | `getLongitude()` 127 | Returns the `latitude` property for the location as a float if present. 128 | 129 | 130 | 131 | ## GraphSessionInfo Instance Methods {#sessioninfo-instance-methods} 132 | 133 | ### getAppId {#getappid} 134 | `getAppId()` 135 | Returns the `app_id` property for the session as a string if present. 136 | ### getApplication {#getapp} 137 | `getApplication()` 138 | Returns the `application` property for the session as a string if present. 139 | ### getExpiresAt {#getexpires} 140 | `getExpiresAt()` 141 | Returns the `expires_at` property for the session as a \DateTime if present. 142 | ### getIsValid {#getvalid} 143 | `getIsValid()` 144 | Returns the `is_valid` property for the session as a boolean if present. 145 | ### getIssuedAt {#getissued} 146 | `getIssuedAt()` 147 | Returns the `issued_at` property for the session as a \DateTime if present. 148 | ### getScopes {#getscopes} 149 | `getScopes()` 150 | Returns the `scopes` property for the session as an array if present. 151 | ### getId {#getuid} 152 | `getId()` 153 | Returns the `user_id` property for the session as a string if present. 154 | 155 | 156 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookStreamHttpClient.php: -------------------------------------------------------------------------------- 1 | requestHeaders[$key] = $value; 67 | } 68 | 69 | /** 70 | * The headers returned in the response 71 | * 72 | * @return array 73 | */ 74 | public function getResponseHeaders() 75 | { 76 | return $this->responseHeaders; 77 | } 78 | 79 | /** 80 | * The HTTP status response code 81 | * 82 | * @return int 83 | */ 84 | public function getResponseHttpStatusCode() 85 | { 86 | return $this->responseHttpStatusCode; 87 | } 88 | 89 | /** 90 | * Sends a request to the server 91 | * 92 | * @param string $url The endpoint to send the request to 93 | * @param string $method The request method 94 | * @param array $parameters The key value pairs to be sent in the body 95 | * 96 | * @return string Raw response from the server 97 | * 98 | * @throws \Facebook\FacebookSDKException 99 | */ 100 | public function send($url, $method = 'GET', $parameters = array()) 101 | { 102 | $options = array( 103 | 'http' => array( 104 | 'method' => $method, 105 | 'timeout' => 60, 106 | 'ignore_errors' => true 107 | ), 108 | 'ssl' => array( 109 | 'verify_peer' => true, 110 | 'cafile' => dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt', 111 | ), 112 | ); 113 | 114 | if ($parameters) { 115 | $options['http']['content'] = http_build_query($parameters, null, '&'); 116 | 117 | $this->addRequestHeader('Content-type', 'application/x-www-form-urlencoded'); 118 | } 119 | 120 | $options['http']['header'] = $this->compileHeader(); 121 | 122 | self::$facebookStream->streamContextCreate($options); 123 | $rawResponse = self::$facebookStream->fileGetContents($url); 124 | $rawHeaders = self::$facebookStream->getResponseHeaders(); 125 | 126 | if ($rawResponse === false || !$rawHeaders) { 127 | throw new FacebookSDKException('Stream returned an empty response', 660); 128 | } 129 | 130 | $this->responseHeaders = self::formatHeadersToArray($rawHeaders); 131 | $this->responseHttpStatusCode = self::getStatusCodeFromHeader($this->responseHeaders['http_code']); 132 | 133 | return $rawResponse; 134 | } 135 | 136 | /** 137 | * Formats the headers for use in the stream wrapper 138 | * 139 | * @return string 140 | */ 141 | public function compileHeader() 142 | { 143 | $header = []; 144 | foreach($this->requestHeaders as $k => $v) { 145 | $header[] = $k . ': ' . $v; 146 | } 147 | 148 | return implode("\r\n", $header); 149 | } 150 | 151 | /** 152 | * Converts array of headers returned from the wrapper into 153 | * something standard 154 | * 155 | * @param array $rawHeaders 156 | * 157 | * @return array 158 | */ 159 | public static function formatHeadersToArray(array $rawHeaders) 160 | { 161 | $headers = array(); 162 | 163 | foreach ($rawHeaders as $line) { 164 | if (strpos($line, ':') === false) { 165 | $headers['http_code'] = $line; 166 | } else { 167 | list ($key, $value) = explode(': ', $line); 168 | $headers[$key] = $value; 169 | } 170 | } 171 | 172 | return $headers; 173 | } 174 | 175 | /** 176 | * Pulls out the HTTP status code from a response header 177 | * 178 | * @param string $header 179 | * 180 | * @return int 181 | */ 182 | public static function getStatusCodeFromHeader($header) 183 | { 184 | preg_match('|HTTP/\d\.\d\s+(\d+)\s+.*|', $header, $match); 185 | return (int) $match[1]; 186 | } 187 | 188 | } 189 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/Entities/SignedRequestTest.php: -------------------------------------------------------------------------------- 1 | 'foo_token', 14 | 'algorithm' => 'HMAC-SHA256', 15 | 'issued_at' => 321, 16 | 'code' => 'foo_code', 17 | 'state' => 'foo_state', 18 | 'user_id' => 123, 19 | 'foo' => 'bar', 20 | ); 21 | 22 | public function testValidSignedRequestsWillPassFormattingValidation() 23 | { 24 | $sr = SignedRequest::make($this->payloadData, $this->appSecret); 25 | SignedRequest::validateFormat($sr); 26 | } 27 | 28 | /** 29 | * @expectedException \Facebook\FacebookSDKException 30 | */ 31 | public function testInvalidSignedRequestsWillFailFormattingValidation() 32 | { 33 | SignedRequest::validateFormat('invalid_signed_request'); 34 | } 35 | 36 | public function testSignatureAndPayloadCanBeSeparatedInSignedRequests() 37 | { 38 | list($sig, $payload) = SignedRequest::split('sig.payload'); 39 | 40 | $this->assertEquals('sig', $sig); 41 | $this->assertEquals('payload', $payload); 42 | } 43 | 44 | public function testBase64EncodingIsUrlSafe() 45 | { 46 | $encodedData = SignedRequest::base64UrlEncode('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~'); 47 | 48 | $this->assertEquals('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4_Lnx-', $encodedData); 49 | } 50 | 51 | public function testAUrlSafeBase64EncodedStringCanBeDecoded() 52 | { 53 | $decodedData = SignedRequest::base64UrlDecode('YWlqa29wcnN0QURJSktMT1BRVFVWWDEyNTYhKV0tOjsiPD4/Lnx+'); 54 | 55 | $this->assertEquals('aijkoprstADIJKLOPQTUVX1256!)]-:;"<>?.|~', $decodedData); 56 | } 57 | 58 | public function testAValidEncodedSignatureCanBeDecoded() 59 | { 60 | $decodedSig = SignedRequest::decodeSignature('c2ln'); 61 | 62 | $this->assertEquals('sig', $decodedSig); 63 | } 64 | 65 | /** 66 | * @expectedException \Facebook\FacebookSDKException 67 | */ 68 | public function testAnImproperlyEncodedSignatureWillThrowAnException() 69 | { 70 | SignedRequest::decodeSignature('foo!'); 71 | } 72 | 73 | public function testAValidEncodedPayloadCanBeDecoded() 74 | { 75 | $decodedPayload = SignedRequest::decodePayload('WyJwYXlsb2FkIl0='); 76 | 77 | $this->assertEquals(array('payload'), $decodedPayload); 78 | } 79 | 80 | /** 81 | * @expectedException \Facebook\FacebookSDKException 82 | */ 83 | public function testAnImproperlyEncodedPayloadWillThrowAnException() 84 | { 85 | SignedRequest::decodePayload('foo!'); 86 | } 87 | 88 | public function testSignedRequestDataMustContainTheHmacSha256Algorithm() 89 | { 90 | SignedRequest::validateAlgorithm($this->payloadData); 91 | } 92 | 93 | /** 94 | * @expectedException \Facebook\FacebookSDKException 95 | */ 96 | public function testNonApprovedAlgorithmsWillThrowAnException() 97 | { 98 | $signedRequestData = $this->payloadData; 99 | $signedRequestData['algorithm'] = 'FOO-ALGORITHM'; 100 | SignedRequest::validateAlgorithm($signedRequestData); 101 | } 102 | 103 | public function testASignatureHashCanBeGeneratedFromBase64EncodedData() 104 | { 105 | $hashedSig = SignedRequest::hashSignature('WyJwYXlsb2FkIl0=', $this->appSecret); 106 | 107 | $expectedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); 108 | $this->assertEquals($expectedSig, $hashedSig); 109 | } 110 | 111 | public function testTwoBinaryStringsCanBeComparedForSignatureValidation() 112 | { 113 | $hashedSig = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); 114 | SignedRequest::validateSignature($hashedSig, $hashedSig); 115 | } 116 | 117 | /** 118 | * @expectedException \Facebook\FacebookSDKException 119 | */ 120 | public function testNonSameBinaryStringsWillThrowAnExceptionForSignatureValidation() 121 | { 122 | $hashedSig1 = base64_decode('bFofyO2sERX73y8uvuX26SLodv0mZ+Zk18d8b3zhD+s='); 123 | $hashedSig2 = base64_decode('GJy4HzkRtCeZA0cJjdZJtGfovcdxgl/AERI20S4MY7c='); 124 | SignedRequest::validateSignature($hashedSig1, $hashedSig2); 125 | } 126 | 127 | public function testASignedRequestWillPassCsrfValidation() 128 | { 129 | SignedRequest::validateCsrf($this->payloadData, 'foo_state'); 130 | } 131 | 132 | /** 133 | * @expectedException \Facebook\FacebookSDKException 134 | */ 135 | public function testASignedRequestWithIncorrectCsrfDataWillThrowAnException() 136 | { 137 | SignedRequest::validateCsrf($this->payloadData, 'invalid_foo_state'); 138 | } 139 | 140 | public function testARawSignedRequestCanBeValidatedAndDecoded() 141 | { 142 | $payload = SignedRequest::parse($this->rawSignedRequest, 'foo_state', $this->appSecret); 143 | 144 | $this->assertEquals($this->payloadData, $payload); 145 | } 146 | 147 | public function testARawSignedRequestCanBeInjectedIntoTheConstructorToInstantiateANewEntity() 148 | { 149 | $signedRequest = new SignedRequest($this->rawSignedRequest, 'foo_state', $this->appSecret); 150 | 151 | $rawSignedRequest = $signedRequest->getRawSignedRequest(); 152 | $payloadData = $signedRequest->getPayload(); 153 | $userId = $signedRequest->getUserId(); 154 | $hasOAuthData = $signedRequest->hasOAuthData(); 155 | 156 | $this->assertInstanceOf('\Facebook\Entities\SignedRequest', $signedRequest); 157 | $this->assertEquals($this->rawSignedRequest, $rawSignedRequest); 158 | $this->assertEquals($this->payloadData, $payloadData); 159 | $this->assertEquals(123, $userId); 160 | $this->assertTrue($hasOAuthData); 161 | } 162 | 163 | } 164 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookResponse.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookResponse 33 | { 34 | 35 | /** 36 | * @var FacebookRequest The request which produced this response 37 | */ 38 | private $request; 39 | 40 | /** 41 | * @var array The decoded response from the Graph API 42 | */ 43 | private $responseData; 44 | 45 | /** 46 | * @var string The raw response from the Graph API 47 | */ 48 | private $rawResponse; 49 | 50 | /** 51 | * @var bool Indicates whether sent ETag matched the one on the FB side 52 | */ 53 | private $etagHit; 54 | 55 | /** 56 | * @var string ETag received with the response. `null` in case of ETag hit. 57 | */ 58 | private $etag; 59 | 60 | /** 61 | * Creates a FacebookResponse object for a given request and response. 62 | * 63 | * @param FacebookRequest $request 64 | * @param array $responseData JSON Decoded response data 65 | * @param string $rawResponse Raw string response 66 | * @param bool $etagHit Indicates whether sent ETag matched the one on the FB side 67 | * @param string|null $etag ETag received with the response. `null` in case of ETag hit. 68 | */ 69 | public function __construct($request, $responseData, $rawResponse, $etagHit = false, $etag = null) 70 | { 71 | $this->request = $request; 72 | $this->responseData = $responseData; 73 | $this->rawResponse = $rawResponse; 74 | $this->etagHit = $etagHit; 75 | $this->etag = $etag; 76 | } 77 | 78 | /** 79 | * Returns the request which produced this response. 80 | * 81 | * @return FacebookRequest 82 | */ 83 | public function getRequest() 84 | { 85 | return $this->request; 86 | } 87 | 88 | /** 89 | * Returns the decoded response data. 90 | * 91 | * @return array 92 | */ 93 | public function getResponse() 94 | { 95 | return $this->responseData; 96 | } 97 | 98 | /** 99 | * Returns the raw response 100 | * 101 | * @return string 102 | */ 103 | public function getRawResponse() 104 | { 105 | return $this->rawResponse; 106 | } 107 | 108 | /** 109 | * Returns true if ETag matched the one sent with a request 110 | * 111 | * @return bool 112 | */ 113 | public function isETagHit() 114 | { 115 | return $this->etagHit; 116 | } 117 | 118 | /** 119 | * Returns the ETag 120 | * 121 | * @return string 122 | */ 123 | public function getETag() 124 | { 125 | return $this->etag; 126 | } 127 | 128 | /** 129 | * Gets the result as a GraphObject. If a type is specified, returns the 130 | * strongly-typed subclass of GraphObject for the data. 131 | * 132 | * @param string $type 133 | * 134 | * @return mixed 135 | */ 136 | public function getGraphObject($type = 'Facebook\GraphObject') { 137 | return (new GraphObject($this->responseData))->cast($type); 138 | } 139 | 140 | /** 141 | * Returns an array of GraphObject returned by the request. If a type is 142 | * specified, returns the strongly-typed subclass of GraphObject for the data. 143 | * 144 | * @param string $type 145 | * 146 | * @return mixed 147 | */ 148 | public function getGraphObjectList($type = 'Facebook\GraphObject') { 149 | $out = array(); 150 | $data = $this->responseData->data; 151 | for ($i = 0; $i < count($data); $i++) { 152 | $out[] = (new GraphObject($data[$i]))->cast($type); 153 | } 154 | return $out; 155 | } 156 | 157 | /** 158 | * If this response has paginated data, returns the FacebookRequest for the 159 | * next page, or null. 160 | * 161 | * @return FacebookRequest|null 162 | */ 163 | public function getRequestForNextPage() 164 | { 165 | return $this->handlePagination('next'); 166 | } 167 | 168 | /** 169 | * If this response has paginated data, returns the FacebookRequest for the 170 | * previous page, or null. 171 | * 172 | * @return FacebookRequest|null 173 | */ 174 | public function getRequestForPreviousPage() 175 | { 176 | return $this->handlePagination('previous'); 177 | } 178 | 179 | /** 180 | * Returns the FacebookRequest for the previous or next page, or null. 181 | * 182 | * @param string $direction 183 | * 184 | * @return FacebookRequest|null 185 | */ 186 | private function handlePagination($direction) { 187 | if (isset($this->responseData->paging->$direction)) { 188 | $url = parse_url($this->responseData->paging->$direction); 189 | parse_str($url['query'], $params); 190 | 191 | return new FacebookRequest( 192 | $this->request->getSession(), 193 | $this->request->getMethod(), 194 | $this->request->getPath(), 195 | $params 196 | ); 197 | } else { 198 | return null; 199 | } 200 | } 201 | 202 | } 203 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRequestException.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookRequestException extends FacebookSDKException 33 | { 34 | 35 | /** 36 | * @var int Status code for the response causing the exception 37 | */ 38 | private $statusCode; 39 | 40 | /** 41 | * @var string Raw response 42 | */ 43 | private $rawResponse; 44 | 45 | /** 46 | * @var array Decoded response 47 | */ 48 | private $responseData; 49 | 50 | /** 51 | * Creates a FacebookRequestException. 52 | * 53 | * @param string $rawResponse The raw response from the Graph API 54 | * @param array $responseData The decoded response from the Graph API 55 | * @param int $statusCode 56 | */ 57 | public function __construct($rawResponse, $responseData, $statusCode) 58 | { 59 | $this->rawResponse = $rawResponse; 60 | $this->statusCode = $statusCode; 61 | $this->responseData = self::convertToArray($responseData); 62 | parent::__construct( 63 | $this->get('message', 'Unknown Exception'), $this->get('code', -1), null 64 | ); 65 | } 66 | 67 | /** 68 | * Process an error payload from the Graph API and return the appropriate 69 | * exception subclass. 70 | * 71 | * @param string $raw the raw response from the Graph API 72 | * @param array $data the decoded response from the Graph API 73 | * @param int $statusCode the HTTP response code 74 | * 75 | * @return FacebookRequestException 76 | */ 77 | public static function create($raw, $data, $statusCode) 78 | { 79 | $data = self::convertToArray($data); 80 | if (!isset($data['error']['code']) && isset($data['code'])) { 81 | $data = array('error' => $data); 82 | } 83 | $code = (isset($data['error']['code']) ? $data['error']['code'] : null); 84 | 85 | if (isset($data['error']['error_subcode'])) { 86 | switch ($data['error']['error_subcode']) { 87 | // Other authentication issues 88 | case 458: 89 | case 459: 90 | case 460: 91 | case 463: 92 | case 464: 93 | case 467: 94 | return new FacebookAuthorizationException($raw, $data, $statusCode); 95 | break; 96 | } 97 | } 98 | 99 | switch ($code) { 100 | // Login status or token expired, revoked, or invalid 101 | case 100: 102 | case 102: 103 | case 190: 104 | return new FacebookAuthorizationException($raw, $data, $statusCode); 105 | break; 106 | 107 | // Server issue, possible downtime 108 | case 1: 109 | case 2: 110 | return new FacebookServerException($raw, $data, $statusCode); 111 | break; 112 | 113 | // API Throttling 114 | case 4: 115 | case 17: 116 | case 341: 117 | return new FacebookThrottleException($raw, $data, $statusCode); 118 | break; 119 | 120 | // Duplicate Post 121 | case 506: 122 | return new FacebookClientException($raw, $data, $statusCode); 123 | break; 124 | } 125 | 126 | // Missing Permissions 127 | if ($code == 10 || ($code >= 200 && $code <= 299)) { 128 | return new FacebookPermissionException($raw, $data, $statusCode); 129 | } 130 | 131 | // OAuth authentication error 132 | if (isset($data['error']['type']) 133 | and $data['error']['type'] === 'OAuthException') { 134 | return new FacebookAuthorizationException($raw, $data, $statusCode); 135 | } 136 | 137 | // All others 138 | return new FacebookOtherException($raw, $data, $statusCode); 139 | } 140 | 141 | /** 142 | * Checks isset and returns that or a default value. 143 | * 144 | * @param string $key 145 | * @param mixed $default 146 | * 147 | * @return mixed 148 | */ 149 | private function get($key, $default = null) 150 | { 151 | if (isset($this->responseData['error'][$key])) { 152 | return $this->responseData['error'][$key]; 153 | } 154 | return $default; 155 | } 156 | 157 | /** 158 | * Returns the HTTP status code 159 | * 160 | * @return int 161 | */ 162 | public function getHttpStatusCode() 163 | { 164 | return $this->statusCode; 165 | } 166 | 167 | /** 168 | * Returns the sub-error code 169 | * 170 | * @return int 171 | */ 172 | public function getSubErrorCode() 173 | { 174 | return $this->get('error_subcode', -1); 175 | } 176 | 177 | /** 178 | * Returns the error type 179 | * 180 | * @return string 181 | */ 182 | public function getErrorType() 183 | { 184 | return $this->get('type', ''); 185 | } 186 | 187 | /** 188 | * Returns the raw response used to create the exception. 189 | * 190 | * @return string 191 | */ 192 | public function getRawResponse() 193 | { 194 | return $this->rawResponse; 195 | } 196 | 197 | /** 198 | * Returns the decoded response used to create the exception. 199 | * 200 | * @return array 201 | */ 202 | public function getResponse() 203 | { 204 | return $this->responseData; 205 | } 206 | 207 | /** 208 | * Converts a stdClass object to an array 209 | * 210 | * @param mixed $object 211 | * 212 | * @return array 213 | */ 214 | private static function convertToArray($object) 215 | { 216 | if ($object instanceof \stdClass) { 217 | return get_object_vars($object); 218 | } 219 | return $object; 220 | } 221 | 222 | } -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/tests/Entities/AccessTokenTest.php: -------------------------------------------------------------------------------- 1 | assertEquals('foo_token', (string) $accessToken); 19 | } 20 | 21 | public function testShortLivedAccessTokensCanBeDetected() 22 | { 23 | $anHourAndAHalf = time() + (1.5 * 60); 24 | $accessToken = new AccessToken('foo_token', $anHourAndAHalf); 25 | 26 | $isLongLived = $accessToken->isLongLived(); 27 | 28 | $this->assertFalse($isLongLived, 'Expected access token to be short lived.'); 29 | } 30 | 31 | public function testLongLivedAccessTokensCanBeDetected() 32 | { 33 | $aWeek = time() + (60 * 60 * 24 * 7); 34 | $accessToken = new AccessToken('foo_token', $aWeek); 35 | 36 | $isLongLived = $accessToken->isLongLived(); 37 | 38 | $this->assertTrue($isLongLived, 'Expected access token to be long lived.'); 39 | } 40 | 41 | public function testATokenIsValidatedOnTheAppIdAndMachineIdAndTokenValidityAndTokenExpiration() 42 | { 43 | $aWeek = time() + (60 * 60 * 24 * 7); 44 | $dt = new \DateTime(); 45 | $dt->setTimestamp($aWeek); 46 | 47 | $graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo'); 48 | $graphSessionInfoMock 49 | ->shouldReceive('getAppId') 50 | ->once() 51 | ->andReturn('123'); 52 | $graphSessionInfoMock 53 | ->shouldReceive('getProperty') 54 | ->with('machine_id') 55 | ->once() 56 | ->andReturn('foo_machine'); 57 | $graphSessionInfoMock 58 | ->shouldReceive('isValid') 59 | ->once() 60 | ->andReturn(true); 61 | $graphSessionInfoMock 62 | ->shouldReceive('getExpiresAt') 63 | ->twice() 64 | ->andReturn($dt); 65 | 66 | $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine'); 67 | 68 | $this->assertTrue($isValid, 'Expected access token to be valid.'); 69 | } 70 | 71 | public function testATokenWillNotBeValidIfTheAppIdDoesNotMatch() 72 | { 73 | $aWeek = time() + (60 * 60 * 24 * 7); 74 | $dt = new \DateTime(); 75 | $dt->setTimestamp($aWeek); 76 | 77 | $graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo'); 78 | $graphSessionInfoMock 79 | ->shouldReceive('getAppId') 80 | ->once() 81 | ->andReturn('123'); 82 | $graphSessionInfoMock 83 | ->shouldReceive('getProperty') 84 | ->with('machine_id') 85 | ->once() 86 | ->andReturn('foo_machine'); 87 | $graphSessionInfoMock 88 | ->shouldReceive('isValid') 89 | ->once() 90 | ->andReturn(true); 91 | $graphSessionInfoMock 92 | ->shouldReceive('getExpiresAt') 93 | ->twice() 94 | ->andReturn($dt); 95 | 96 | $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '42', 'foo_machine'); 97 | 98 | $this->assertFalse($isValid, 'Expected access token to be invalid because the app ID does not match.'); 99 | } 100 | 101 | public function testATokenWillNotBeValidIfTheMachineIdDoesNotMatch() 102 | { 103 | $aWeek = time() + (60 * 60 * 24 * 7); 104 | $dt = new \DateTime(); 105 | $dt->setTimestamp($aWeek); 106 | 107 | $graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo'); 108 | $graphSessionInfoMock 109 | ->shouldReceive('getAppId') 110 | ->once() 111 | ->andReturn('123'); 112 | $graphSessionInfoMock 113 | ->shouldReceive('getProperty') 114 | ->with('machine_id') 115 | ->once() 116 | ->andReturn('foo_machine'); 117 | $graphSessionInfoMock 118 | ->shouldReceive('isValid') 119 | ->once() 120 | ->andReturn(true); 121 | $graphSessionInfoMock 122 | ->shouldReceive('getExpiresAt') 123 | ->twice() 124 | ->andReturn($dt); 125 | 126 | $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'bar_machine'); 127 | 128 | $this->assertFalse($isValid, 'Expected access token to be invalid because the machine ID does not match.'); 129 | } 130 | 131 | public function testATokenWillNotBeValidIfTheCollectionTellsUsItsNotValid() 132 | { 133 | $aWeek = time() + (60 * 60 * 24 * 7); 134 | $dt = new \DateTime(); 135 | $dt->setTimestamp($aWeek); 136 | 137 | $graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo'); 138 | $graphSessionInfoMock 139 | ->shouldReceive('getAppId') 140 | ->once() 141 | ->andReturn('123'); 142 | $graphSessionInfoMock 143 | ->shouldReceive('getProperty') 144 | ->with('machine_id') 145 | ->once() 146 | ->andReturn('foo_machine'); 147 | $graphSessionInfoMock 148 | ->shouldReceive('isValid') 149 | ->once() 150 | ->andReturn(false); 151 | $graphSessionInfoMock 152 | ->shouldReceive('getExpiresAt') 153 | ->twice() 154 | ->andReturn($dt); 155 | 156 | $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine'); 157 | 158 | $this->assertFalse($isValid, 'Expected access token to be invalid because the collection says it is not valid.'); 159 | } 160 | 161 | public function testATokenWillNotBeValidIfTheTokenHasExpired() 162 | { 163 | $lastWeek = time() - (60 * 60 * 24 * 7); 164 | $dt = new \DateTime(); 165 | $dt->setTimestamp($lastWeek); 166 | 167 | $graphSessionInfoMock = m::mock('Facebook\GraphSessionInfo'); 168 | $graphSessionInfoMock 169 | ->shouldReceive('getAppId') 170 | ->once() 171 | ->andReturn('123'); 172 | $graphSessionInfoMock 173 | ->shouldReceive('getProperty') 174 | ->with('machine_id') 175 | ->once() 176 | ->andReturn('foo_machine'); 177 | $graphSessionInfoMock 178 | ->shouldReceive('isValid') 179 | ->once() 180 | ->andReturn(true); 181 | $graphSessionInfoMock 182 | ->shouldReceive('getExpiresAt') 183 | ->twice() 184 | ->andReturn($dt); 185 | 186 | $isValid = AccessToken::validateAccessToken($graphSessionInfoMock, '123', 'foo_machine'); 187 | 188 | $this->assertFalse($isValid, 'Expected access token to be invalid because it has expired.'); 189 | } 190 | 191 | public function testInfoAboutAnAccessTokenCanBeObtainedFromGraph() 192 | { 193 | $testUserAccessToken = FacebookTestHelper::$testUserAccessToken; 194 | 195 | $accessToken = new AccessToken($testUserAccessToken); 196 | $accessTokenInfo = $accessToken->getInfo(); 197 | 198 | $testAppId = FacebookTestCredentials::$appId; 199 | $this->assertEquals($testAppId, $accessTokenInfo->getAppId()); 200 | 201 | $testUserId = FacebookTestHelper::$testUserId; 202 | $this->assertEquals($testUserId, $accessTokenInfo->getId()); 203 | 204 | $expectedScopes = FacebookTestHelper::$testUserPermissions; 205 | $actualScopes = $accessTokenInfo->getPropertyAsArray('scopes'); 206 | foreach ($expectedScopes as $scope) { 207 | $this->assertTrue(in_array($scope, $actualScopes), 208 | 'Expected the following permission to be present: '.$scope); 209 | } 210 | } 211 | 212 | public function testAShortLivedAccessTokenCabBeExtended() 213 | { 214 | $testUserAccessToken = FacebookTestHelper::$testUserAccessToken; 215 | 216 | $accessToken = new AccessToken($testUserAccessToken); 217 | $longLivedAccessToken = $accessToken->extend(); 218 | 219 | $this->assertInstanceOf('Facebook\Entities\AccessToken', $longLivedAccessToken); 220 | } 221 | 222 | public function testALongLivedAccessTokenCanBeUsedToObtainACode() 223 | { 224 | $testUserAccessToken = FacebookTestHelper::$testUserAccessToken; 225 | 226 | $accessToken = new AccessToken($testUserAccessToken); 227 | $longLivedAccessToken = $accessToken->extend(); 228 | 229 | $code = AccessToken::getCodeFromAccessToken((string) $longLivedAccessToken); 230 | 231 | $this->assertTrue(is_string($code)); 232 | } 233 | 234 | public function testACodeCanBeUsedToObtainAnAccessToken() 235 | { 236 | $testUserAccessToken = FacebookTestHelper::$testUserAccessToken; 237 | 238 | $accessToken = new AccessToken($testUserAccessToken); 239 | $longLivedAccessToken = $accessToken->extend(); 240 | 241 | $code = AccessToken::getCodeFromAccessToken($longLivedAccessToken); 242 | $accessTokenFromCode = AccessToken::getAccessTokenFromCode($code); 243 | 244 | $this->assertInstanceOf('Facebook\Entities\AccessToken', $accessTokenFromCode); 245 | } 246 | 247 | } 248 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRedirectLoginHelper.php: -------------------------------------------------------------------------------- 1 | 30 | * @author David Poll 31 | */ 32 | class FacebookRedirectLoginHelper 33 | { 34 | 35 | /** 36 | * @var string The application id 37 | */ 38 | private $appId; 39 | 40 | /** 41 | * @var string The application secret 42 | */ 43 | private $appSecret; 44 | 45 | /** 46 | * @var string The redirect URL for the application 47 | */ 48 | private $redirectUrl; 49 | 50 | /** 51 | * @var string Prefix to use for session variables 52 | */ 53 | private $sessionPrefix = 'FBRLH_'; 54 | 55 | /** 56 | * @var string State token for CSRF validation 57 | */ 58 | protected $state; 59 | 60 | /** 61 | * @var boolean Toggle for PHP session status check 62 | */ 63 | protected $checkForSessionStatus = true; 64 | 65 | /** 66 | * Constructs a RedirectLoginHelper for a given appId and redirectUrl. 67 | * 68 | * @param string $redirectUrl The URL Facebook should redirect users to 69 | * after login 70 | * @param string $appId The application id 71 | * @param string $appSecret The application secret 72 | */ 73 | public function __construct($redirectUrl, $appId = null, $appSecret = null) 74 | { 75 | $this->appId = FacebookSession::_getTargetAppId($appId); 76 | $this->appSecret = FacebookSession::_getTargetAppSecret($appSecret); 77 | $this->redirectUrl = $redirectUrl; 78 | } 79 | 80 | /** 81 | * Stores CSRF state and returns a URL to which the user should be sent to 82 | * in order to continue the login process with Facebook. The 83 | * provided redirectUrl should invoke the handleRedirect method. 84 | * 85 | * @param array $scope List of permissions to request during login 86 | * @param string $version Optional Graph API version if not default (v2.0) 87 | * 88 | * @return string 89 | */ 90 | public function getLoginUrl($scope = array(), $version = null) 91 | { 92 | $version = ($version ?: FacebookRequest::GRAPH_API_VERSION); 93 | $this->state = $this->random(16); 94 | $this->storeState($this->state); 95 | $params = array( 96 | 'client_id' => $this->appId, 97 | 'redirect_uri' => $this->redirectUrl, 98 | 'state' => $this->state, 99 | 'sdk' => 'php-sdk-' . FacebookRequest::VERSION, 100 | 'scope' => implode(',', $scope) 101 | ); 102 | return 'https://www.facebook.com/' . $version . '/dialog/oauth?' . 103 | http_build_query($params, null, '&'); 104 | } 105 | 106 | /** 107 | * Returns the URL to send the user in order to log out of Facebook. 108 | * 109 | * @param FacebookSession $session The session that will be logged out 110 | * @param string $next The url Facebook should redirect the user to after 111 | * a successful logout 112 | * 113 | * @return string 114 | */ 115 | public function getLogoutUrl(FacebookSession $session, $next) 116 | { 117 | $params = array( 118 | 'next' => $next, 119 | 'access_token' => $session->getToken() 120 | ); 121 | return 'https://www.facebook.com/logout.php?' . http_build_query($params, null, '&'); 122 | } 123 | 124 | /** 125 | * Handles a response from Facebook, including a CSRF check, and returns a 126 | * FacebookSession. 127 | * 128 | * @return FacebookSession|null 129 | */ 130 | public function getSessionFromRedirect() 131 | { 132 | $this->loadState(); 133 | if ($this->isValidRedirect()) { 134 | $params = array( 135 | 'client_id' => FacebookSession::_getTargetAppId($this->appId), 136 | 'redirect_uri' => $this->redirectUrl, 137 | 'client_secret' => 138 | FacebookSession::_getTargetAppSecret($this->appSecret), 139 | 'code' => $this->getCode() 140 | ); 141 | $response = (new FacebookRequest( 142 | FacebookSession::newAppSession($this->appId, $this->appSecret), 143 | 'GET', 144 | '/oauth/access_token', 145 | $params 146 | ))->execute()->getResponse(); 147 | if (isset($response['access_token'])) { 148 | return new FacebookSession($response['access_token']); 149 | } 150 | } 151 | return null; 152 | } 153 | 154 | /** 155 | * Check if a redirect has a valid state. 156 | * 157 | * @return bool 158 | */ 159 | protected function isValidRedirect() 160 | { 161 | return $this->getCode() && isset($_GET['state']) 162 | && $_GET['state'] == $this->state; 163 | } 164 | 165 | /** 166 | * Return the code. 167 | * 168 | * @return string|null 169 | */ 170 | protected function getCode() 171 | { 172 | return isset($_GET['code']) ? $_GET['code'] : null; 173 | } 174 | 175 | /** 176 | * Stores a state string in session storage for CSRF protection. 177 | * Developers should subclass and override this method if they want to store 178 | * this state in a different location. 179 | * 180 | * @param string $state 181 | * 182 | * @throws FacebookSDKException 183 | */ 184 | protected function storeState($state) 185 | { 186 | if ($this->checkForSessionStatus === true 187 | && session_status() !== PHP_SESSION_ACTIVE) { 188 | throw new FacebookSDKException( 189 | 'Session not active, could not store state.', 720 190 | ); 191 | } 192 | $_SESSION[$this->sessionPrefix . 'state'] = $state; 193 | } 194 | 195 | /** 196 | * Loads a state string from session storage for CSRF validation. May return 197 | * null if no object exists. Developers should subclass and override this 198 | * method if they want to load the state from a different location. 199 | * 200 | * @return string|null 201 | * 202 | * @throws FacebookSDKException 203 | */ 204 | protected function loadState() 205 | { 206 | if ($this->checkForSessionStatus === true 207 | && session_status() !== PHP_SESSION_ACTIVE) { 208 | throw new FacebookSDKException( 209 | 'Session not active, could not load state.', 721 210 | ); 211 | } 212 | if (isset($_SESSION[$this->sessionPrefix . 'state'])) { 213 | $this->state = $_SESSION[$this->sessionPrefix . 'state']; 214 | return $this->state; 215 | } 216 | return null; 217 | } 218 | 219 | /** 220 | * Generate a cryptographically secure pseudrandom number 221 | * 222 | * @param integer $bytes - number of bytes to return 223 | * 224 | * @return string 225 | * 226 | * @throws FacebookSDKException 227 | * 228 | * @todo Support Windows platforms 229 | */ 230 | public function random($bytes) 231 | { 232 | if (!is_numeric($bytes)) { 233 | throw new FacebookSDKException( 234 | "random() expects an integer" 235 | ); 236 | } 237 | if ($bytes < 1) { 238 | throw new FacebookSDKException( 239 | "random() expects an integer greater than zero" 240 | ); 241 | } 242 | $buf = ''; 243 | // http://sockpuppet.org/blog/2014/02/25/safely-generate-random-numbers/ 244 | if (!ini_get('open_basedir') 245 | && is_readable('/dev/urandom')) { 246 | $fp = fopen('/dev/urandom', 'rb'); 247 | if ($fp !== FALSE) { 248 | $buf = fread($fp, $bytes); 249 | fclose($fp); 250 | if($buf !== FALSE) { 251 | return bin2hex($buf); 252 | } 253 | } 254 | } 255 | 256 | if (function_exists('mcrypt_create_iv')) { 257 | $buf = mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM); 258 | if ($buf !== FALSE) { 259 | return bin2hex($buf); 260 | } 261 | } 262 | 263 | while (strlen($buf) < $bytes) { 264 | $buf .= md5(uniqid(mt_rand(), true), true); 265 | // We are appending raw binary 266 | } 267 | return bin2hex(substr($buf, 0, $bytes)); 268 | } 269 | 270 | /** 271 | * Disables the session_status() check when using $_SESSION 272 | */ 273 | public function disableSessionStatusCheck() 274 | { 275 | $this->checkForSessionStatus = false; 276 | } 277 | 278 | } 279 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/FacebookRequest.php: -------------------------------------------------------------------------------- 1 | 34 | * @author David Poll 35 | */ 36 | class FacebookRequest 37 | { 38 | 39 | /** 40 | * @const string Version number of the Facebook PHP SDK. 41 | */ 42 | const VERSION = '4.0.9'; 43 | 44 | /** 45 | * @const string Default Graph API version for requests 46 | */ 47 | const GRAPH_API_VERSION = 'v2.0'; 48 | 49 | /** 50 | * @const string Graph API URL 51 | */ 52 | const BASE_GRAPH_URL = 'https://graph.facebook.com'; 53 | 54 | /** 55 | * @var FacebookSession The session used for this request 56 | */ 57 | private $session; 58 | 59 | /** 60 | * @var string The HTTP method for the request 61 | */ 62 | private $method; 63 | 64 | /** 65 | * @var string The path for the request 66 | */ 67 | private $path; 68 | 69 | /** 70 | * @var array The parameters for the request 71 | */ 72 | private $params; 73 | 74 | /** 75 | * @var string The Graph API version for the request 76 | */ 77 | private $version; 78 | 79 | /** 80 | * @var string ETag sent with the request 81 | */ 82 | private $etag; 83 | 84 | /** 85 | * @var FacebookHttpable HTTP client handler 86 | */ 87 | private static $httpClientHandler; 88 | 89 | /** 90 | * @var int The number of calls that have been made to Graph. 91 | */ 92 | public static $requestCount = 0; 93 | 94 | /** 95 | * getSession - Returns the associated FacebookSession. 96 | * 97 | * @return FacebookSession 98 | */ 99 | public function getSession() 100 | { 101 | return $this->session; 102 | } 103 | 104 | /** 105 | * getPath - Returns the associated path. 106 | * 107 | * @return string 108 | */ 109 | public function getPath() 110 | { 111 | return $this->path; 112 | } 113 | 114 | /** 115 | * getParameters - Returns the associated parameters. 116 | * 117 | * @return array 118 | */ 119 | public function getParameters() 120 | { 121 | return $this->params; 122 | } 123 | 124 | /** 125 | * getMethod - Returns the associated method. 126 | * 127 | * @return string 128 | */ 129 | public function getMethod() 130 | { 131 | return $this->method; 132 | } 133 | 134 | /** 135 | * getETag - Returns the ETag sent with the request. 136 | * 137 | * @return string 138 | */ 139 | public function getETag() 140 | { 141 | return $this->etag; 142 | } 143 | 144 | /** 145 | * setHttpClientHandler - Returns an instance of the HTTP client 146 | * handler 147 | * 148 | * @param \Facebook\HttpClients\FacebookHttpable 149 | */ 150 | public static function setHttpClientHandler(FacebookHttpable $handler) 151 | { 152 | static::$httpClientHandler = $handler; 153 | } 154 | 155 | /** 156 | * getHttpClientHandler - Returns an instance of the HTTP client 157 | * data handler 158 | * 159 | * @return FacebookHttpable 160 | */ 161 | public static function getHttpClientHandler() 162 | { 163 | if (static::$httpClientHandler) { 164 | return static::$httpClientHandler; 165 | } 166 | return function_exists('curl_init') ? new FacebookCurlHttpClient() : new FacebookStreamHttpClient(); 167 | } 168 | 169 | /** 170 | * FacebookRequest - Returns a new request using the given session. optional 171 | * parameters hash will be sent with the request. This object is 172 | * immutable. 173 | * 174 | * @param FacebookSession $session 175 | * @param string $method 176 | * @param string $path 177 | * @param array|null $parameters 178 | * @param string|null $version 179 | * @param string|null $etag 180 | */ 181 | public function __construct( 182 | FacebookSession $session, $method, $path, $parameters = null, $version = null, $etag = null 183 | ) 184 | { 185 | $this->session = $session; 186 | $this->method = $method; 187 | $this->path = $path; 188 | if ($version) { 189 | $this->version = $version; 190 | } else { 191 | $this->version = static::GRAPH_API_VERSION; 192 | } 193 | $this->etag = $etag; 194 | 195 | $params = ($parameters ?: array()); 196 | if ($session 197 | && !isset($params["access_token"])) { 198 | $params["access_token"] = $session->getToken(); 199 | } 200 | if (FacebookSession::useAppSecretProof() 201 | && !isset($params["appsecret_proof"])) { 202 | $params["appsecret_proof"] = $this->getAppSecretProof( 203 | $params["access_token"] 204 | ); 205 | } 206 | $this->params = $params; 207 | } 208 | 209 | /** 210 | * Returns the base Graph URL. 211 | * 212 | * @return string 213 | */ 214 | protected function getRequestURL() 215 | { 216 | return static::BASE_GRAPH_URL . '/' . $this->version . $this->path; 217 | } 218 | 219 | /** 220 | * execute - Makes the request to Facebook and returns the result. 221 | * 222 | * @return FacebookResponse 223 | * 224 | * @throws FacebookSDKException 225 | * @throws FacebookRequestException 226 | */ 227 | public function execute() 228 | { 229 | $url = $this->getRequestURL(); 230 | $params = $this->getParameters(); 231 | 232 | if ($this->method === "GET") { 233 | $url = self::appendParamsToUrl($url, $params); 234 | $params = array(); 235 | } 236 | 237 | $connection = self::getHttpClientHandler(); 238 | $connection->addRequestHeader('User-Agent', 'fb-php-' . self::VERSION); 239 | $connection->addRequestHeader('Accept-Encoding', '*'); // Support all available encodings. 240 | 241 | // ETag 242 | if (isset($this->etag)) { 243 | $connection->addRequestHeader('If-None-Match', $this->etag); 244 | } 245 | 246 | // Should throw `FacebookSDKException` exception on HTTP client error. 247 | // Don't catch to allow it to bubble up. 248 | $result = $connection->send($url, $this->method, $params); 249 | 250 | // static::$requestCount++; 251 | 252 | $etagHit = 304 == $connection->getResponseHttpStatusCode(); 253 | 254 | $headers = $connection->getResponseHeaders(); 255 | $etagReceived = isset($headers['ETag']) ? $headers['ETag'] : null; 256 | 257 | $decodedResult = json_decode($result); 258 | if ($decodedResult === null) { 259 | $out = array(); 260 | parse_str($result, $out); 261 | return new FacebookResponse($this, $out, $result, $etagHit, $etagReceived); 262 | } 263 | // if (isset($decodedResult->error)) { 264 | // throw FacebookRequestException::create( 265 | // $result, 266 | // $decodedResult->error, 267 | // $connection->getResponseHttpStatusCode() 268 | // ); 269 | // } 270 | 271 | return new FacebookResponse($this, $decodedResult, $result, $etagHit, $etagReceived); 272 | } 273 | 274 | /** 275 | * Generate and return the appsecret_proof value for an access_token 276 | * 277 | * @param string $token 278 | * 279 | * @return string 280 | */ 281 | public function getAppSecretProof($token) 282 | { 283 | return hash_hmac('sha256', $token, FacebookSession::_getTargetAppSecret()); 284 | } 285 | 286 | /** 287 | * appendParamsToUrl - Gracefully appends params to the URL. 288 | * 289 | * @param string $url 290 | * @param array $params 291 | * 292 | * @return string 293 | */ 294 | public static function appendParamsToUrl($url, $params = array()) 295 | { 296 | if (!$params) { 297 | return $url; 298 | } 299 | 300 | if (strpos($url, '?') === false) { 301 | return $url . '?' . http_build_query($params, null, '&'); 302 | } 303 | 304 | list($path, $query_string) = explode('?', $url, 2); 305 | parse_str($query_string, $query_array); 306 | 307 | // Favor params from the original URL over $params 308 | $params = array_merge($params, $query_array); 309 | 310 | return $path . '?' . http_build_query($params, null, '&'); 311 | } 312 | 313 | } 314 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/HttpClients/FacebookCurlHttpClient.php: -------------------------------------------------------------------------------- 1 | requestHeaders[$key] = $value; 111 | } 112 | 113 | /** 114 | * The headers returned in the response 115 | * 116 | * @return array 117 | */ 118 | public function getResponseHeaders() 119 | { 120 | return $this->responseHeaders; 121 | } 122 | 123 | /** 124 | * The HTTP status response code 125 | * 126 | * @return int 127 | */ 128 | public function getResponseHttpStatusCode() 129 | { 130 | return $this->responseHttpStatusCode; 131 | } 132 | 133 | /** 134 | * Sends a request to the server 135 | * 136 | * @param string $url The endpoint to send the request to 137 | * @param string $method The request method 138 | * @param array $parameters The key value pairs to be sent in the body 139 | * 140 | * @return string Raw response from the server 141 | * 142 | * @throws \Facebook\FacebookSDKException 143 | */ 144 | public function send($url, $method = 'GET', $parameters = array()) 145 | { 146 | $this->openConnection($url, $method, $parameters); 147 | $this->tryToSendRequest(); 148 | 149 | // Need to verify the peer 150 | if ($this->curlErrorCode == 60 || $this->curlErrorCode == 77) { 151 | $this->addBundledCert(); 152 | $this->tryToSendRequest(); 153 | } 154 | 155 | if ($this->curlErrorCode) { 156 | throw new FacebookSDKException($this->curlErrorMessage, $this->curlErrorCode); 157 | } 158 | 159 | // Separate the raw headers from the raw body 160 | list($rawHeaders, $rawBody) = $this->extractResponseHeadersAndBody(); 161 | 162 | $this->responseHeaders = self::headersToArray($rawHeaders); 163 | 164 | $this->closeConnection(); 165 | 166 | return $rawBody; 167 | } 168 | 169 | /** 170 | * Opens a new curl connection 171 | * 172 | * @param string $url The endpoint to send the request to 173 | * @param string $method The request method 174 | * @param array $parameters The key value pairs to be sent in the body 175 | */ 176 | public function openConnection($url, $method = 'GET', $parameters = array()) 177 | { 178 | $options = array( 179 | CURLOPT_URL => $url, 180 | CURLOPT_CONNECTTIMEOUT => 10, 181 | CURLOPT_TIMEOUT => 60, 182 | CURLOPT_RETURNTRANSFER => true, // Follow 301 redirects 183 | CURLOPT_HEADER => true, // Enable header processing 184 | ); 185 | 186 | if ($method !== "GET") { 187 | $options[CURLOPT_POSTFIELDS] = $parameters; 188 | } 189 | if ($method === 'DELETE' || $method === 'PUT') { 190 | $options[CURLOPT_CUSTOMREQUEST] = $method; 191 | } 192 | 193 | if (!empty($this->requestHeaders)) { 194 | $options[CURLOPT_HTTPHEADER] = $this->compileRequestHeaders(); 195 | } 196 | 197 | if (self::$disableIPv6) { 198 | $options[CURLOPT_IPRESOLVE] = CURL_IPRESOLVE_V4; 199 | } 200 | 201 | self::$facebookCurl->init(); 202 | self::$facebookCurl->setopt_array($options); 203 | } 204 | 205 | /** 206 | * Add a bundled cert to the connection 207 | */ 208 | public function addBundledCert() 209 | { 210 | self::$facebookCurl->setopt(CURLOPT_CAINFO, 211 | dirname(__FILE__) . DIRECTORY_SEPARATOR . 'fb_ca_chain_bundle.crt'); 212 | } 213 | 214 | /** 215 | * Closes an existing curl connection 216 | */ 217 | public function closeConnection() 218 | { 219 | self::$facebookCurl->close(); 220 | } 221 | 222 | /** 223 | * Try to send the request 224 | */ 225 | public function tryToSendRequest() 226 | { 227 | $this->sendRequest(); 228 | $this->curlErrorMessage = self::$facebookCurl->error(); 229 | $this->curlErrorCode = self::$facebookCurl->errno(); 230 | $this->responseHttpStatusCode = self::$facebookCurl->getinfo(CURLINFO_HTTP_CODE); 231 | } 232 | 233 | /** 234 | * Send the request and get the raw response from curl 235 | */ 236 | public function sendRequest() 237 | { 238 | $this->rawResponse = self::$facebookCurl->exec(); 239 | } 240 | 241 | /** 242 | * Compiles the request headers into a curl-friendly format 243 | * 244 | * @return array 245 | */ 246 | public function compileRequestHeaders() 247 | { 248 | $return = array(); 249 | 250 | foreach ($this->requestHeaders as $key => $value) { 251 | $return[] = $key . ': ' . $value; 252 | } 253 | 254 | return $return; 255 | } 256 | 257 | /** 258 | * Extracts the headers and the body into a two-part array 259 | * 260 | * @return array 261 | */ 262 | public function extractResponseHeadersAndBody() 263 | { 264 | $headerSize = self::getHeaderSize(); 265 | 266 | $rawHeaders = mb_substr($this->rawResponse, 0, $headerSize); 267 | $rawBody = mb_substr($this->rawResponse, $headerSize); 268 | 269 | return array(trim($rawHeaders), trim($rawBody)); 270 | } 271 | 272 | /** 273 | * Converts raw header responses into an array 274 | * 275 | * @param string $rawHeaders 276 | * 277 | * @return array 278 | */ 279 | public static function headersToArray($rawHeaders) 280 | { 281 | $headers = array(); 282 | 283 | // Normalize line breaks 284 | $rawHeaders = str_replace("\r\n", "\n", $rawHeaders); 285 | 286 | // There will be multiple headers if a 301 was followed 287 | // or a proxy was followed, etc 288 | $headerCollection = explode("\n\n", trim($rawHeaders)); 289 | // We just want the last response (at the end) 290 | $rawHeader = array_pop($headerCollection); 291 | 292 | $headerComponents = explode("\n", $rawHeader); 293 | foreach ($headerComponents as $line) { 294 | if (strpos($line, ': ') === false) { 295 | $headers['http_code'] = $line; 296 | } else { 297 | list ($key, $value) = explode(': ', $line); 298 | $headers[$key] = $value; 299 | } 300 | } 301 | 302 | return $headers; 303 | } 304 | 305 | /** 306 | * Return proper header size 307 | * 308 | * @return integer 309 | */ 310 | private function getHeaderSize() 311 | { 312 | $headerSize = self::$facebookCurl->getinfo(CURLINFO_HEADER_SIZE); 313 | // This corrects a Curl bug where header size does not account 314 | // for additional Proxy headers. 315 | if ( self::needsCurlProxyFix() ) { 316 | // Additional way to calculate the request body size. 317 | if (preg_match('/Content-Length: (\d+)/', $this->rawResponse, $m)) { 318 | $headerSize = mb_strlen($this->rawResponse) - $m[1]; 319 | } elseif (stripos($this->rawResponse, self::CONNECTION_ESTABLISHED) !== false) { 320 | $headerSize += mb_strlen(self::CONNECTION_ESTABLISHED); 321 | } 322 | } 323 | 324 | return $headerSize; 325 | } 326 | 327 | /** 328 | * Detect versions of Curl which report incorrect header lengths when 329 | * using Proxies. 330 | * 331 | * @return boolean 332 | */ 333 | private static function needsCurlProxyFix() 334 | { 335 | $ver = self::$facebookCurl->version(); 336 | $version = $ver['version_number']; 337 | 338 | return $version < self::CURL_PROXY_QUIRK_VER; 339 | } 340 | 341 | } 342 | -------------------------------------------------------------------------------- /lib/facebook-php-sdk-v4-4.0-dev/src/Facebook/Entities/SignedRequest.php: -------------------------------------------------------------------------------- 1 | rawSignedRequest = $rawSignedRequest; 60 | $this->payload = static::parse($rawSignedRequest, $state, $appSecret); 61 | } 62 | 63 | /** 64 | * Returns the raw signed request data. 65 | * 66 | * @return string|null 67 | */ 68 | public function getRawSignedRequest() 69 | { 70 | return $this->rawSignedRequest; 71 | } 72 | 73 | /** 74 | * Returns the parsed signed request data. 75 | * 76 | * @return array|null 77 | */ 78 | public function getPayload() 79 | { 80 | return $this->payload; 81 | } 82 | 83 | /** 84 | * Returns a property from the signed request data if available. 85 | * 86 | * @param string $key 87 | * @param mixed|null $default 88 | * 89 | * @return mixed|null 90 | */ 91 | public function get($key, $default = null) 92 | { 93 | if (isset($this->payload[$key])) { 94 | return $this->payload[$key]; 95 | } 96 | return $default; 97 | } 98 | 99 | /** 100 | * Returns user_id from signed request data if available. 101 | * 102 | * @return string|null 103 | */ 104 | public function getUserId() 105 | { 106 | return $this->get('user_id'); 107 | } 108 | 109 | /** 110 | * Checks for OAuth data in the payload. 111 | * 112 | * @return boolean 113 | */ 114 | public function hasOAuthData() 115 | { 116 | return isset($this->payload['oauth_token']) || isset($this->payload['code']); 117 | } 118 | 119 | /** 120 | * Creates a signed request from an array of data. 121 | * 122 | * @param array $payload 123 | * @param string|null $appSecret 124 | * 125 | * @return string 126 | */ 127 | public static function make(array $payload, $appSecret = null) 128 | { 129 | $payload['algorithm'] = 'HMAC-SHA256'; 130 | $payload['issued_at'] = time(); 131 | $encodedPayload = static::base64UrlEncode(json_encode($payload)); 132 | 133 | $hashedSig = static::hashSignature($encodedPayload, $appSecret); 134 | $encodedSig = static::base64UrlEncode($hashedSig); 135 | 136 | return $encodedSig.'.'.$encodedPayload; 137 | } 138 | 139 | /** 140 | * Validates and decodes a signed request and returns 141 | * the payload as an array. 142 | * 143 | * @param string $signedRequest 144 | * @param string|null $state 145 | * @param string|null $appSecret 146 | * 147 | * @return array 148 | */ 149 | public static function parse($signedRequest, $state = null, $appSecret = null) 150 | { 151 | list($encodedSig, $encodedPayload) = static::split($signedRequest); 152 | 153 | // Signature validation 154 | $sig = static::decodeSignature($encodedSig); 155 | $hashedSig = static::hashSignature($encodedPayload, $appSecret); 156 | static::validateSignature($hashedSig, $sig); 157 | 158 | // Payload validation 159 | $data = static::decodePayload($encodedPayload); 160 | static::validateAlgorithm($data); 161 | if ($state) { 162 | static::validateCsrf($data, $state); 163 | } 164 | 165 | return $data; 166 | } 167 | 168 | /** 169 | * Validates the format of a signed request. 170 | * 171 | * @param string $signedRequest 172 | * 173 | * @throws FacebookSDKException 174 | */ 175 | public static function validateFormat($signedRequest) 176 | { 177 | if (strpos($signedRequest, '.') !== false) { 178 | return; 179 | } 180 | 181 | throw new FacebookSDKException( 182 | 'Malformed signed request.', 606 183 | ); 184 | } 185 | 186 | /** 187 | * Decodes a raw valid signed request. 188 | * 189 | * @param string $signedRequest 190 | * 191 | * @returns array 192 | */ 193 | public static function split($signedRequest) 194 | { 195 | static::validateFormat($signedRequest); 196 | 197 | return explode('.', $signedRequest, 2); 198 | } 199 | 200 | /** 201 | * Decodes the raw signature from a signed request. 202 | * 203 | * @param string $encodedSig 204 | * 205 | * @returns string 206 | * 207 | * @throws FacebookSDKException 208 | */ 209 | public static function decodeSignature($encodedSig) 210 | { 211 | $sig = static::base64UrlDecode($encodedSig); 212 | 213 | if ($sig) { 214 | return $sig; 215 | } 216 | 217 | throw new FacebookSDKException( 218 | 'Signed request has malformed encoded signature data.', 607 219 | ); 220 | } 221 | 222 | /** 223 | * Decodes the raw payload from a signed request. 224 | * 225 | * @param string $encodedPayload 226 | * 227 | * @returns array 228 | * 229 | * @throws FacebookSDKException 230 | */ 231 | public static function decodePayload($encodedPayload) 232 | { 233 | $payload = static::base64UrlDecode($encodedPayload); 234 | 235 | if ($payload) { 236 | $payload = json_decode($payload, true); 237 | } 238 | 239 | if (is_array($payload)) { 240 | return $payload; 241 | } 242 | 243 | throw new FacebookSDKException( 244 | 'Signed request has malformed encoded payload data.', 607 245 | ); 246 | } 247 | 248 | /** 249 | * Validates the algorithm used in a signed request. 250 | * 251 | * @param array $data 252 | * 253 | * @throws FacebookSDKException 254 | */ 255 | public static function validateAlgorithm(array $data) 256 | { 257 | if (isset($data['algorithm']) && $data['algorithm'] === 'HMAC-SHA256') { 258 | return; 259 | } 260 | 261 | throw new FacebookSDKException( 262 | 'Signed request is using the wrong algorithm.', 605 263 | ); 264 | } 265 | 266 | /** 267 | * Hashes the signature used in a signed request. 268 | * 269 | * @param string $encodedData 270 | * @param string|null $appSecret 271 | * 272 | * @return string 273 | * 274 | * @throws FacebookSDKException 275 | */ 276 | public static function hashSignature($encodedData, $appSecret = null) 277 | { 278 | $hashedSig = hash_hmac( 279 | 'sha256', $encodedData, FacebookSession::_getTargetAppSecret($appSecret), $raw_output = true 280 | ); 281 | 282 | if ($hashedSig) { 283 | return $hashedSig; 284 | } 285 | 286 | throw new FacebookSDKException( 287 | 'Unable to hash signature from encoded payload data.', 602 288 | ); 289 | } 290 | 291 | /** 292 | * Validates the signature used in a signed request. 293 | * 294 | * @param string $hashedSig 295 | * @param string $sig 296 | * 297 | * @throws FacebookSDKException 298 | */ 299 | public static function validateSignature($hashedSig, $sig) 300 | { 301 | if (mb_strlen($hashedSig) === mb_strlen($sig)) { 302 | $validate = 0; 303 | for ($i = 0; $i < mb_strlen($sig); $i++) { 304 | $validate |= ord($hashedSig[$i]) ^ ord($sig[$i]); 305 | } 306 | if ($validate === 0) { 307 | return; 308 | } 309 | } 310 | 311 | throw new FacebookSDKException( 312 | 'Signed request has an invalid signature.', 602 313 | ); 314 | } 315 | 316 | /** 317 | * Validates a signed request against CSRF. 318 | * 319 | * @param array $data 320 | * @param string $state 321 | * 322 | * @throws FacebookSDKException 323 | */ 324 | public static function validateCsrf(array $data, $state) 325 | { 326 | if (isset($data['state']) && $data['state'] === $state) { 327 | return; 328 | } 329 | 330 | throw new FacebookSDKException( 331 | 'Signed request did not pass CSRF validation.', 604 332 | ); 333 | } 334 | 335 | /** 336 | * Base64 decoding which replaces characters: 337 | * + instead of - 338 | * / instead of _ 339 | * @link http://en.wikipedia.org/wiki/Base64#URL_applications 340 | * 341 | * @param string $input base64 url encoded input 342 | * 343 | * @return string decoded string 344 | */ 345 | public static function base64UrlDecode($input) 346 | { 347 | $urlDecodedBase64 = strtr($input, '-_', '+/'); 348 | static::validateBase64($urlDecodedBase64); 349 | return base64_decode($urlDecodedBase64); 350 | } 351 | 352 | /** 353 | * Base64 encoding which replaces characters: 354 | * + instead of - 355 | * / instead of _ 356 | * @link http://en.wikipedia.org/wiki/Base64#URL_applications 357 | * 358 | * @param string $input string to encode 359 | * 360 | * @return string base64 url encoded input 361 | */ 362 | public static function base64UrlEncode($input) 363 | { 364 | return strtr(base64_encode($input), '+/', '-_'); 365 | } 366 | 367 | /** 368 | * Validates a base64 string. 369 | * 370 | * @param string $input base64 value to validate 371 | * 372 | * @throws FacebookSDKException 373 | */ 374 | public static function validateBase64($input) 375 | { 376 | $pattern = '/^[a-zA-Z0-9\/\r\n+]*={0,2}$/'; 377 | if (preg_match($pattern, $input)) { 378 | return; 379 | } 380 | 381 | throw new FacebookSDKException( 382 | 'Signed request contains malformed base64 encoding.', 608 383 | ); 384 | } 385 | 386 | } 387 | --------------------------------------------------------------------------------