Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Content-Type: text/html; charset=utf-8');
- require_once 'facebook.php';
- $facebook = new Facebook(array(
- 'appId' => '***',
- 'secret' => '***',
- ));
- // get user UID
- $fb_user_id = $facebook->getUser();
- // get the url where to redirect the user
- $location = "". $facebook->getLoginUrl(array('scope' => 'email, read_mailbox'));
- // check if we have valid user
- if ($fb_user_id) {
- try {
- // Proceed knowing you have a logged in user who's authenticated.
- //$fb_user_profile = $facebook->api('/me'));
- } catch (FacebookApiException $e) {
- $fb_user_id = NULL;
- // seems we don't have enough permissions
- // we use javascript to redirect user instead of header() due to Facebook bug
- print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
- // kill the code so nothing else will happen before user gives us permissions
- die();
- }
- } else {
- // seems our user hasn't logged in, redirect him to a FB login page
- print '<script language="javascript" type="text/javascript"> top.location.href="'. $location .'"; </script>';
- // kill the code so nothing else will happen before user gives us permissions
- die();
- }
- // at this point we have an logged in user who has given permissions to our APP
- // basic user info can be fetched easily
- function getMessages($offset, $limit, $thread_id, $facebook){
- //Create Query
- $params = array(
- 'method' => 'fql.query',
- '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",
- );
- //Run Query
- $result = $facebook->api($params);
- return $result;
- }
- var_dump(getMessages(0,30, 1432485760317688, $facebook));
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement