使用php分页的Facebook API列表收件箱
我想通过facebook API-PHP查看facebook消息列表。 我用php写了一段代码,ı写了代码使用php分页的Facebook API列表收件箱,php,facebook,api,list,inbox,Php,Facebook,Api,List,Inbox,我想通过facebook API-PHP查看facebook消息列表。 我用php写了一段代码,ı写了代码 // Facebook App Connection $facebook = new Facebook(array( 'appId' => 'xxxxxxxxxxxx', 'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx', )); $user = $fac
// Facebook App Connection
$facebook = new Facebook(array(
'appId' => 'xxxxxxxxxxxx',
'secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxx',
));
$user = $facebook->getUser();
if($user) {
try
{
$params = array(
'fields' => 'inbox',
);
$user_profile = $facebook->api('/me',$params);
}
catch (FacebookApiException $e)
{
error_log($e);
$user = null;
}
}
print_r($user_profile);
/* Output:
Array
(
[id] => xxxxxxxxxx
[inbox] => Array
(
[data] => Array
(
[0] => Array
(
[id] => xxxxxxxxxxxxxx
[to] => Array
(
[data] => Array
(
[0] => Array
(
[name] => John Doe
[id] => xxxxxxxxxx
)
[1] => Array
(
[name] => Jane Doe
[id] => xxxxxxxxxx
)
)
)
[updated_time] => 2013-01-13T21:33:34+0000
[unread] => 2
[unseen] => 1
[comments] => Array
(
[data] => Array
(
[0] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => Jane Doe
[id] => xxxxxxxxxx
)
[message] => Hi!
[created_time] => 2013-01-13T19:15:49+0000
)
[1] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => John Doe
[id] => xxxxxxxxxx
)
[message] => Hi,How are you?
[created_time] => 2013-01-13T19:15:54+0000
)
[2] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => Jane Doe
[id] => xxxxxxxxxx
)
[message] => Fine but have a problem facebook api
[created_time] => 2013-01-13T19:16:03+0000
)
[3] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => John Doe
[id] => xxxxxxxxxx
)
[message] => what problem?
[created_time] => 2013-01-13T19:16:25+0000
)
[4] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => Jane Doe
[id] => xxxxxxxxxx
)
[message] => not list all messages in inbox
[created_time] => 2013-01-13T21:04:37+0000
)
[5] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => John Doe
[id] => xxxxxxxxxx
)
[message] => I can't help
[created_time] => 2013-01-13T21:04:40+0000
)
.bla
.bla
.bla
.bla
.bla
.bla
[24] => Array
(
[id] => xxxxxxxxxxxxxx_xxxx
[from] => Array
(
[name] => John Doe
[id] => xxxxxxxxxx
)
[message] => Okey,bye
[created_time] => 2013-01-13T21:33:34+0000
)
)
[paging] => Array
(
[previous] => https://graph.facebook.com/377285305670598/comments?limit=25&since=1358112814&__paging_token=377285305670598_2394&__previous=1
[next] => https://graph.facebook.com/377285305670598/comments?limit=25&until=1358104549&__paging_token=377285305670598_2370
)
)
)
*/
我想要输出无名氏:嗨
你好,你好吗?
简·多伊:很好,但facebook api有问题
约翰·多伊:什么问题?
Jane Doe:未列出收件箱中的所有邮件
约翰·多伊:我无能为力
约翰·多伊:好的,再见
我编写了代码强>
for($i=0; $i <= 5; $i++){
foreach($data as $a):
foreach($a[$i] as $id => $to):
foreach($to as $data):
foreach($data as $key => $value):
echo $value["name"]."=>".$value["message"];
endforeach;
endforeach;
endforeach;
endforeach;
endforeach;
echo "<br/>";
对于($i=0;$i$to):
foreach($至$数据):
foreach($key=>$value形式的数据):
echo$value[“name”]。“=>”$value[“message”];
endforeach;
endforeach;
endforeach;
endforeach;
endforeach;
回声“
”;
我的结果无名氏=>
约翰·多伊=>
=>嗨
=>嗨,你好吗?
=>很好,但facebook api有问题
=>什么问题?
=>不列出收件箱中的所有邮件
=>我无能为力
…布拉
…布拉
…布拉
=>我无能为力
h=>h
h=>h 我想查看所有邮件和发件人姓名。我试着去做
1-获取下一个url和文件内容($url);-不工作。
2-分配限制和偏移-不工作
如何编写代码?我想这就是你想要的
foreach($user_profile as $main){
foreach($main as $a){
foreach($a as $b){
foreach($b as $c){
foreach($c as $d){
foreach($d as $e){
if(strlen($e["name"]) > 1){
echo "<b>".$e["name"].":</b>";
}
}
echo $d["message"]."</br>\n";
}
}
}
}
}
foreach($user\u profile作为$main){
foreach($a的主要部分){
foreach($a为$b){
foreach($b为$c){
foreach($c作为$d){
外汇兑换($d为$e){
如果(strlen($e[“name”])>1){
回声“$e[“名称”]。:”;
}
}
回显$d[“消息”]。“\n”;
}
}
}
}
}
这将对您有所帮助
<h1>Inbox Start</h1>
<?php
$inbox = $user_profile["inbox"]["data"];
foreach ($inbox as $data){ ?>
<h3>To: </h3>
<?php
foreach ($data["to"]["data"] as $to){
?>
<a href="http://www.facebook.com/<?php echo $to["id"]?>" target="_blank"><?php echo $to["name"]?></a>
<?php
}
?>
<h3>Last Reply: </h3>
<?php echo date("d M, Y H:i:s",strtotime($data["updated_time"]))?>
<h3>Message Read: </h3>
<?php if($data["unread"]==1){ echo "Unread";}else { echo "Read";}?>
<h3>Message Seen: </h3>
<?php if($data["unseen"]==1){ echo "Unseen";}else { echo "Seen";}?>
<h3>Comment: </h3>
<?php
$comments = $data["comments"]["data"];
foreach ($comments as $comment){
?>
<div>
<div style="float:left; width:50px;">
<img src="https://graph.facebook.com/<?php echo $comment['from']['id']?>/picture?width=50&height=50" />
</div>
<div style="float:left; margin-left:10px;">
<strong style="color: #AF2D2D;"> <?php echo $comment['from']['name']?></strong> <br />
<p style="color: gray !important;"><?php echo date("d M, Y H:i:s",strtotime($comment["created_time"]));?></p>
</div>
<div style="clear:both; margin-bottom:10px;"></div>
<div style="width:500px; color: #AF2D2D;">
<?php echo $comment['message'] ?>
</div>
</div>
<?php
}
?>
<hr><bR>
<?php
}
?>
收件箱启动
致:
最后答复:
留言如下:
看到的消息:
评论:
/图片?宽度=50,高度=50“/>