Advertisement
terorama

fbn / fbsync.inc.php

Dec 22nd, 2012
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.85 KB | None | 0 0
  1. <?php
  2.  
  3. require('params.inc.php');
  4.  
  5. class fbSync {
  6.  
  7.  
  8.    const SCOPESTR ='user_about_me,  user_activities,  user_birthday,  user_checkins,
  9.      user_education_history,  user_events,  user_groups,  user_hometown,  user_interests,
  10.      user_likes,  user_location,  user_notes,  user_photos,  user_questions,  user_relationships,
  11.      user_relationship_details,  user_religion_politics,  user_status,  user_subscriptions,
  12.      user_videos,  user_website,  user_work_history,  email,
  13.      read_friendlists,  read_insights,  read_mailbox,  read_requests,  read_stream,
  14.      xmpp_login,  ads_management,  create_event,  manage_friendlists,
  15.      manage_notifications,  user_online_presence,  friends_online_presence,
  16.      publish_checkins,  publish_stream,  rsvp_event';
  17.  
  18.    private $facebook;
  19.    private $user;
  20.  
  21.    //--------------------------------------------------------------
  22.    //                  connect
  23.    //--------------------------------------------------------------
  24.    public function __construct() {
  25.    
  26.        require 'facebook.php';
  27.      
  28.        $this->facebook = new Facebook(array(
  29.             'appId'  => APPID,
  30.             'secret' => SECRETID ,
  31.          ));
  32.          
  33.       if (!$this->facebook)
  34.          throw new Exception('failed to init facebook PHP SDK');
  35.          
  36.       $this->user = $this->facebook->getUser();
  37.    }
  38.    
  39.    //--------------------------------------------------------------
  40.    //                    get user
  41.    //--------------------------------------------------------------  
  42.    public function getUser() {
  43.    
  44.       return $this->user;
  45.      
  46.    }
  47.    
  48.    //--------------------------------------------------------------
  49.    //                    get login url
  50.    //--------------------------------------------------------------  
  51.    public function getLoginUrl($redir_uri) {
  52.    
  53.       return  $this->facebook->getLoginUrl(array(
  54.         'redirect_uri' => 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].
  55.         '?redir='.$redir_uri,                  
  56.         'scope'=> fbSync::SCOPESTR
  57.       ));
  58.      
  59.    }
  60.    
  61.    //--------------------------------------------------------------
  62.    //                    get logout url
  63.    //--------------------------------------------------------------  
  64.    public function getLogoutUrl($redir_uri) {
  65.    
  66.      return $this->facebook->getLogoutUrl(array('next' => 'http://'.
  67.      $_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'].'?redir='.$redir_uri));
  68.  
  69.    }
  70.    
  71.    //--------------------------------------------------------------
  72.    //                   save last error  
  73.    //--------------------------------------------------------------  
  74.     private function saveError($e, $mtname, $args) {
  75.    
  76.       $s = 'Exception: '.$e->getType().':'.$e->getMessage()."\r\n";
  77.       $s.= 'in method: '.$mtname."\r\n";
  78.       $s.= 'arguments: '.implode(',',$args)."\r\n\r\n";
  79.      
  80.       return $s;
  81.    }  
  82.    
  83.    //---------------------------------------------get GraphApi node
  84.    public function getNode($inf) {
  85.  
  86.       if (!$this->facebook)
  87.          $this->connect();
  88.    
  89.       $s=array();
  90.       try {
  91.          $s= $this->facebook->api($inf);     
  92.       }
  93.       catch (FacebookApiException $e) {
  94.          $args =  func_get_args();
  95.          $s['err'] = $this->saveError($e, __METHOD__,$args);
  96.          
  97.       }
  98.      
  99.      return $s;
  100.    }
  101.  
  102.    //-----------------------------------------------------get Fql
  103.    public function get_fql($query) {
  104.    
  105.       if (!$this->facebook)
  106.          $this->connect();
  107.  
  108.       $inf = array();
  109.      
  110.       $param = array(
  111.                      'method'=> 'fql.query',
  112.                      'query'=>str_replace('\"','"',$query));
  113.       try {
  114.          $inf = $this->facebook->api($param);
  115.       }
  116.      
  117.       catch (FacebookApiException $e) {
  118.          $args = func_get_args();
  119.          $inf['err'] = $this->saveError($e, __METHOD__, $args);
  120.       }
  121.      
  122.       return $inf;                       
  123.    }
  124.    
  125.    
  126.      
  127.    
  128.    
  129.    
  130. }
  131.  
  132.  
  133.  
  134.  
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement