0

requesting assistance to understand how to display inbox messages via API. basically, i just want to retrieve the sender and the message in my inbox.

Extended Permissions: read_mailbox permission is already allowed.

below code works. i just need to know how to properly create a new call for the inbox messages via JSON format and decode the result.

require '../src/facebook.php';
$facebook = new Facebook(array(
  'appId'  => 'xxx',
  'secret' => 'xxx',
));

// Get User ID
$user = $facebook->getUser();

if ($user) {
  try {
    // Proceed knowing you have a logged in user who's authenticated.
    $user_profile = $facebook->api('/me');
  } catch (FacebookApiException $e) {
    error_log($e);
    $user = null;
  }
}

if ($user) {
  $logoutUrl = $facebook->getLogoutUrl();
} else {
  $loginUrl = $facebook->getLoginUrl();
}

$getUser= $facebook->api('/me');
echo $getUser['name'];

at first, ive tried adding below.

$getInbox = $facebook->api('/me/inbox');
echo $getInbox['message'];

but it renders error on my PHP.

bobbyjones
  • 2,029
  • 9
  • 28
  • 47

1 Answers1

2

Using the Graph API, you need to authenticate the user with additional permissions:

<?php
$loginUrl = $facebook->getLoginUrl([
    'scope' => 'email, read_mailbox, read_requests'
]);

Now that you have the additional permissions, you can access the information using this script:

<?php
$user_mail = $facebook->api('/me?fields=id,name,inbox.limit(10)');
print_r($user_mail);
Kirk Beard
  • 9,569
  • 12
  • 43
  • 47