Advertisement
Guest User

Untitled

a guest
Jan 26th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.86 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3. require_once 'facebook.php';
  4.  
  5. $facebook = new Facebook(array(
  6.     'appId'  => '***',
  7.     'secret' => '***',
  8. ));
  9.  
  10. // get user UID
  11. $fb_user_id = $facebook->getUser();
  12.  
  13.     // get the url where to redirect the user
  14. $location = "". $facebook->getLoginUrl(array('scope' => 'email, read_mailbox'));
  15.  
  16. // check if we have valid user
  17. if ($fb_user_id) {
  18.     try {
  19.         // Proceed knowing you have a logged in user who's authenticated.
  20.         //$fb_user_profile = $facebook->api('/me'));  
  21.  
  22.     } catch (FacebookApiException $e) {
  23.         $fb_user_id = NULL;
  24.         // seems we don't have enough permissions
  25.         // we use javascript to redirect user instead of header() due to Facebook bug
  26.         print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
  27.  
  28.         // kill the code so nothing else will happen before user gives us permissions
  29.         die();
  30.     }
  31.  
  32. } else {
  33.     // seems our user hasn't logged in, redirect him to a FB login page
  34.  
  35.     print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
  36.  
  37.     // kill the code so nothing else will happen before user gives us permissions
  38.     die();
  39. }
  40.  
  41. // at this point we have an logged in user who has given permissions to our APP
  42. // basic user info can be fetched easily
  43.  
  44. function getMessages($offset, $limit, $thread_id, $facebook){
  45.     //Create Query
  46.     $params = array(
  47.         'method' => 'fql.query',
  48.         'query' => "SELECT attachment,author_id,created_time,body FROM message WHERE viewer_id = me() AND thread_id = $thread_id ORDER BY created_time DESC LIMIT $offset,$limit",
  49.     );
  50.  
  51.     //Run Query
  52.     $result = $facebook->api($params);
  53.     return $result;
  54. }
  55.  
  56.  
  57.     var_dump(getMessages(0,30, 1432485760317688, $facebook));
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement