通过Facebook API收到收件箱消息 [英] getting inbox message via facebook API

查看:249
本文介绍了通过Facebook API收到收件箱消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请求帮助以了解如何通过API显示收件箱消息。基本上,我只想在收件箱中检索发件人和邮件。

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.

扩展权限:read_mailbox 权限是已经允许。

以下代码工作。我只需要知道如何通过JSON格式正确地为收件箱消息创建新的调用并解码结果。

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'];

起初,ive尝试添加下面。

at first, ive tried adding below.

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

但它会在我的PHP上显示错误。

but it renders error on my PHP.

推荐答案

使用Graph API,您需要对附加权限的用户进行身份验证:

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);

这篇关于通过Facebook API收到收件箱消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆