Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
facebook

facebook

Ratings: (0)|Views: 244|Likes:
Published by anon_607592

More info:

Published by: anon_607592 on Feb 03, 2011
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as TXT, PDF, TXT or read online from Scribd
See more
See less

05/04/2013

pdf

text

original

 
<?php// Copyright 2004-2009 Facebook. All Rights Reserved.//// +---------------------------------------------------------------------------+// Facebook Platform PHP5 client // +---------------------------------------------------------------------------+// Copyright (c) 2007 Facebook, Inc. // All rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions // are met: // // 1. Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // 2. Redistributions in binary form must reproduce the above copyright // notice, this list of conditions and the following disclaimer in the // documentation and/or other materials provided with the distribution. // // THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR //  IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES // OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. // IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, //  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT //  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT //  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF // THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // +---------------------------------------------------------------------------+// For help with this library, contact developers-help@facebook.com // +---------------------------------------------------------------------------+include_once 'facebookapi_php5_restlib.php';define('FACEBOOK_API_VALIDATION_ERROR', 1);class Facebook {public $api_client;public $api_key;public $secret;public $generate_session_secret;public $session_expires;public $fb_params;public $user;public $profile_user;public $canvas_user;public $ext_perms = array();protected $base_domain;/** Create a Facebook client like this:** $fb = new Facebook(API_KEY, SECRET);** This will automatically pull in any parameters, validate them against the* session signature, and chuck them in the public $fb_params member variable.** @param api_key your Developer API key* @param secret your Developer API secret
 
* @param generate_session_secret whether to automatically generate a session* if the user doesn't have one, but* there is an auth token present in the url,*/public function __construct($api_key, $secret, $generate_session_secret=false){$this->api_key = $api_key;$this->secret = $secret;$this->generate_session_secret = $generate_session_secret;$this->api_client = new FacebookRestClient($api_key, $secret, null);$this->validate_fb_params();// Set the default user id for methods that allow the caller to// pass an explicit uid instead of using a session key.$defaultUser = null;if ($this->user) {$defaultUser = $this->user;} else if ($this->profile_user) {$defaultUser = $this->profile_user;} else if ($this->canvas_user) {$defaultUser = $this->canvas_user;}$this->api_client->set_user($defaultUser);if (isset($this->fb_params['friends'])) {$this->api_client->friends_list =array_filter(explode(',', $this->fb_params['friends']));}if (isset($this->fb_params['added'])) {$this->api_client->added = $this->fb_params['added'];}if (isset($this->fb_params['canvas_user'])) {$this->api_client->canvas_user = $this->fb_params['canvas_user'];}}/** Validates that the parameters passed in were sent from Facebook. It does so* by validating that the signature matches one that could only be generated* by using your application's secret key.** Facebook-provided parameters will come from $_POST, $_GET, or $_COOKIE,* in that order. $_POST and $_GET are always more up-to-date than cookies,* so we prefer those if they are available.** For nitty-gritty details of when each of these is used, check out* http://wiki.developers.facebook.com/index.php/Verifying_The_Signature*/public function validate_fb_params() {$this->fb_params = $this->get_valid_fb_params($_POST, 48 * 3600, 'fb_sig');// note that with preload FQL, it's possible to receive POST params in// addition to GET, so use a different prefix to differentiate themif (!$this->fb_params) {$fb_params = $this->get_valid_fb_params($_GET, 48 * 3600, 'fb_sig');$fb_post_params = $this->get_valid_fb_params($_POST,48 * 3600, // 48 hours'fb_post_sig');
 
$this->fb_params = array_merge($fb_params, $fb_post_params);}// Okay, something came in via POST or GETif ($this->fb_params) {$user = isset($this->fb_params['user']) ?$this->fb_params['user'] : null;$this->profile_user = isset($this->fb_params['profile_user']) ?$this->fb_params['profile_user'] : null;$this->canvas_user = isset($this->fb_params['canvas_user']) ?$this->fb_params['canvas_user'] : null;$this->base_domain = isset($this->fb_params['base_domain']) ?$this->fb_params['base_domain'] : null;$this->ext_perms = isset($this->fb_params['ext_perms']) ?explode(',', $this->fb_params['ext_perms']): array();if (isset($this->fb_params['session_key'])) {$session_key = $this->fb_params['session_key'];} else if (isset($this->fb_params['profile_session_key'])) {$session_key = $this->fb_params['profile_session_key'];} else {$session_key = null;}$expires = isset($this->fb_params['expires']) ?$this->fb_params['expires'] : null;$this->set_user($user,$session_key,$expires);} else if ($cookies =$this->get_valid_fb_params($_COOKIE, null, $this->api_key)) {// if no Facebook parameters were found in the GET or POST variables,// then fall back to cookies, which may have cached user information// Cookies are also used to receive session data via the Javascript API$base_domain_cookie = 'base_domain_' . $this->api_key;if (isset($_COOKIE[$base_domain_cookie])) {$this->base_domain = $_COOKIE[$base_domain_cookie];}// use $api_key . '_' as a prefix for the cookies in case there are// multiple facebook clients on the same domain.$expires = isset($cookies['expires']) ? $cookies['expires'] : null;$this->set_user($cookies['user'],$cookies['session_key'],$expires);}return !empty($this->fb_params);}// Store a temporary session secret for the current session// for use with the JS client librarypublic function promote_session() {try {$session_secret = $this->api_client->auth_promoteSession();if (!$this->in_fb_canvas()) {$this->set_cookies($this->user, $this->api_client->session_key, $this->session_expires, $session_secret);}return $session_secret;

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->