Advertisement
obernardovieira

API Facebook get graph values

Jan 1st, 2014
362
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.79 KB | None | 0 0
  1. <?php
  2. require_once('facebook-php-sdk-master/src/base_facebook.php');
  3. require_once('facebook-php-sdk-master/src/facebook.php');
  4.  
  5. // Credentials
  6. $fb_app_id = '324097137728196';
  7. $fb_app_secret = 'e67f4a3eaed41bd9167643efb3ecac39';
  8.  
  9. $facebook = new Facebook(array('appId'=>$fb_app_id, 'secret'=>$fb_app_secret, 'cookie'=>true));
  10.  
  11. // Permissions
  12. $allow = 'email,user_status';
  13.  
  14. $loginurl = $facebook->getLoginUrl(array('scope'=>$allow/*, 'display'=>'popup'*/));
  15.  
  16. $get_fb_user = $facebook->getUser();
  17.  
  18. // Offline
  19. if (is_null($get_fb_user) or $get_fb_user == 0) {
  20.    
  21.     header("Location: {$loginurl} ");
  22.     exit;
  23.    
  24. // Online
  25. } else {
  26.    
  27.     try {
  28.        
  29.         // Verify
  30.         $facebook->api($get_fb_user);
  31.        
  32.         // Token
  33.         $service_token = $facebook->getAccessToken();
  34.        
  35.         // User Details
  36.         $fql = "SELECT uid, email, username, name, pic_square, locale FROM user WHERE uid = me()";
  37.         $user = $facebook->api(array('method'=>'fql.query', 'query'=>$fql));
  38.        
  39.        
  40.         echo '
  41.        <ul>
  42.            <li>User id: '.$user['0']['uid'].'</li>
  43.            <li>User email: '.$user['0']['email'].'</li>
  44.            <li>User name: '.$user['0']['name'].'</li>
  45.             <li>User username: '.$user['0']['username'].'</li>
  46.             <li>User locale: '.$user['0']['locale'].'</li>
  47.        </ul>';
  48.  
  49.     $nameuser = $user['0']['name']
  50.        
  51.         $url = "http://graph.facebook.com/$nameuser/picture?type=large";
  52.  
  53.         $headers = get_headers($url, 1);
  54.  
  55.         if( isset($headers['Location']) ) {
  56.             echo '<img src='.$headers['Location'].'>';
  57.             //copy($headers['Location'],'obernardovieira.jpg');
  58.         }
  59.         else {
  60.             echo "ERROR";
  61.         }
  62.        
  63.     } catch (FacebookApiException $e) {
  64.        
  65.         header("Location: {$loginurl} ");
  66.         exit;
  67.     }
  68.    
  69. }
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement