使用PHP分页Facebook的API列表收件箱 [英] Facebook API list inbox using php paging

查看:182
本文介绍了使用PHP分页Facebook的API列表收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过Facebook API的PHP Facebook的邮件列表。
我写了一个code,使用PHP,我写了code;

I want list of facebook messages through Facebook API-PHP. I wrote a code with php, ı wrote the code;

     // 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结果
李四:什么问题结果
李四:没有列出收件箱中搜索所有消息
李四:我不禁结果
李四:欧凯,再见结果

I want to output;
Jane Doe: Hi!
John Doe: Hi,how are you?
Jane Doe: Fine but have a problem facebook api
John Doe: What problem?
Jane Doe: not list all messages in inbox
John Doe: I can't help
John Doe: Okey,bye

我写了code;

      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/>";

我的结果; 结果
李四=>结果
李四=>结果
=>嗨!结果
=>你怎么样?结果
=>不错,但有一个问题Facebook的API结果
=>什么问题?结果
=>没有列出收件箱中搜索所有消息
=>我不禁结果
... BLA结果
... BLA结果
... BLA结果
=>我不禁结果
H => ^ h结果
H => ^ h

My result;
Jane Doe=>
John Doe=>
=>Hi!
=>Hi, How are you?
=>Fine but have a problem facebook api
=>What problem?
=>not list all messages in inbox
=>I can't help
...bla
...bla
...bla
=>I can't help
h=>h
h=>h

我想看到的所有邮件和发送者名称。我尝试过了;结果
1 - 获取下一个URL和file_get_content($网址); - 不工作结果。
2 - Assing限制和偏移 - 不工作结果
如何写一个code?

I want see all messages and sender name. I tried to;
1- Getting next url and file_get_content($url); - not working.
2- Assing limit and offset - not working
How to write a code?

推荐答案

这会帮助你。

<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> &nbsp; 
        <?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   
    }
  ?>

这篇关于使用PHP分页Facebook的API列表收件箱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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