how to display facebook inbox messages without user session

Hi everyone.I am trying to display the facebook mesages into our website without login into faceboo throgh our app.When we login into facebook through our app we are able to display their facebook messages.But we are not getting the messages by passing userid without login.How to get this.
Here is my code

<?php include_once("config.php"); $username=$_SESSION['UserName']; $conn = mysql_connect('localhost','xxxxxxxx','xxxxxxxx'); if(!$conn) { die("MySQL connection failed: ". mysqli_connect_error()); } $sql = "select fb_userid from `tb_integration` where Username='$username' and Status='Active' and Integrationype='facebook' "; mysql_select_db('omniveacrm'); $retval = mysql_query( $sql); if(!empty($retval)) { try { echo "
"; while($row = mysql_fetch_array($retval, MYSQL_NUM)) { $fb_userid="{$row[0]}"; $multiQuery = array( "query1"=>"SELECT thread_id, subject, updated_time, parent_message_id, message_count, snippet, object_id, unread, viewer_id FROM thread WHERE folder_id = '0' AND viewer_id='$fb_userid'", "query2"=>"SELECT message_id,author_id,body,viewer_id, thread_id FROM message WHERE thread_id IN (SELECT thread_id FROM #query1)", "query3"=>"SELECT name, uid,pic FROM user WHERE uid IN (SELECT author_id FROM #query2)", ); $param = array( 'method' => 'fql.multiquery', 'queries' => $multiQuery, 'callback' => '' ); $queryresults = $facebook->api($param); print_r($queryresults); $bold="bold"; Color="activecaption"; foreach($queryresults[0]['fql_result_set'] as $thread){ foreach($queryresults[1]['fql_result_set'] as $message){ $message_ = $message; foreach($queryresults[2]['fql_result_set'] as $name){ if($name['uid'] == $message['author_id']){ $name_ = $name; $profilepic1=$name["pic"]; echo '
'; echo ''; echo '
'; echo '
'.$name["name"].'
'; echo $message["body"]; echo ""; } } } } } } catch (FacebookApiException $e) { echo '
'.htmlspecialchars(print_r($e, true)).'
'; $fbuser = null; } } else { include_once("fbconfig.php"); if ($fbuser) { try { $user_profile = $facebook->api('/me'); $fql_query = 'SELECT page_id, name, page_url FROM page WHERE page_id IN (SELECT page_id FROM page_admin WHERE uid='.$fbuser.')'; $postResults = $facebook->api(array( 'method' => 'fql.query', 'query' => $fql_query )); $bold="bold"; $result = array(); $result1 = $fql_query[0]; $Color="activecaption"; } catch (FacebookApiException $e) { echo $e->getMessage(); $fbuser = null; } }else{ $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)); echo ''; $fbuser = null; } if($fbuser && empty($postResults)) { $loginUrl = $facebook->getLoginUrl(array('redirect_uri'=>$homeurl,'scope'=>$fbPermissions)); echo '
Could not get your page details!'; echo '
Click here to try again!'; }elseif($fbuser && !empty($postResults)){ ?> <?php foreach($postResults as $postResult){ $page_id= $postResult['page_id']; $facebook="facebook"; $status="Active"; $username=$_SESSION['UserName']; $conn = mysql_connect('localhost','omniveacrm','omniveacrm@123'); if(!$conn) { die("MySQL connection failed: ". mysqli_connect_error()); } $sql = "INSERT INTO `tb_integration`(Integrationype,Username,Password,Status,page_id,fb_userid,CreatedOn) values ('{$facebook}','{$_SESSION['UserName']}',{$_SESSION['Password']}','{$status}','{$page_id}','{$fbuser}',now())"; mysql_select_db('omniveacrm'); $result1 = mysql_query( $sql); if($result1) { } else { echo 'Error! Failed to insert the file' . "
{$conn->error}
"; } echo ''; ?> <?php } } } ?>

Thank you in advance

Sponsor our Newsletter | Privacy Policy | Terms of Service