Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require('params.inc.php');
- class fbSync {
- const SCOPESTR ='user_about_me, user_activities, user_birthday, user_checkins,
- user_education_history, user_events, user_groups, user_hometown, user_interests,
- user_likes, user_location, user_notes, user_photos, user_questions, user_relationships,
- user_relationship_details, user_religion_politics, user_status, user_subscriptions,
- user_videos, user_website, user_work_history, email,
- read_friendlists, read_insights, read_mailbox, read_requests, read_stream,
- xmpp_login, ads_management, create_event, manage_friendlists,
- manage_notifications, user_online_presence, friends_online_presence,
- publish_checkins, publish_stream, rsvp_event';
- private $facebook;
- private $user;
- //--------------------------------------------------------------
- // connect
- //--------------------------------------------------------------
- public function __construct() {
- require 'facebook.php';
- $this->facebook = new Facebook(array(
- 'appId' => APPID,
- 'secret' => SECRETID ,
- ));
- if (!$this->facebook)
- throw new Exception('failed to init facebook PHP SDK');
- $this->user = $this->facebook->getUser();
- }
- //--------------------------------------------------------------
- // get user
- //--------------------------------------------------------------
- public function getUser() {
- return $this->user;
- }
- //--------------------------------------------------------------
- // get login url
- //--------------------------------------------------------------
- public function getLoginUrl($redir_uri) {
- return $this->facebook->getLoginUrl(array(
- 'redirect_uri' => 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].
- '?redir='.$redir_uri,
- 'scope'=> fbSync::SCOPESTR
- ));
- }
- //--------------------------------------------------------------
- // get logout url
- //--------------------------------------------------------------
- public function getLogoutUrl($redir_uri) {
- return $this->facebook->getLogoutUrl(array('next' => 'http://'.
- $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?redir='.$redir_uri));
- }
- //--------------------------------------------------------------
- // save last error
- //--------------------------------------------------------------
- private function saveError($e, $mtname, $args) {
- $s = 'Exception: '.$e->getType().':'.$e->getMessage()."\r\n";
- $s.= 'in method: '.$mtname."\r\n";
- $s.= 'arguments: '.implode(',',$args)."\r\n\r\n";
- return $s;
- }
- //---------------------------------------------get GraphApi node
- public function getNode($inf) {
- if (!$this->facebook)
- $this->connect();
- $s=array();
- try {
- $s= $this->facebook->api($inf);
- }
- catch (FacebookApiException $e) {
- $args = func_get_args();
- $s['err'] = $this->saveError($e, __METHOD__,$args);
- }
- return $s;
- }
- //-----------------------------------------------------get Fql
- public function get_fql($query) {
- if (!$this->facebook)
- $this->connect();
- $inf = array();
- $param = array(
- 'method'=> 'fql.query',
- 'query'=>str_replace('\"','"',$query));
- try {
- $inf = $this->facebook->api($param);
- }
- catch (FacebookApiException $e) {
- $args = func_get_args();
- $inf['err'] = $this->saveError($e, __METHOD__, $args);
- }
- return $inf;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement