Facebook API-PHP を介して Facebook メッセージのリストが必要です。私はphpでコードを書きました。私はコードを書きました。
// 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
)
)
)
*/
出力したい;
ジェーン・ドウ: こんにちは!
ジョン・ドウ: こんにちは、お元気ですか?
Jane Doe: 結構ですが、問題があります facebook api
John Doe: 何の問題ですか?
Jane Doe: 受信トレイのすべてのメッセージを一覧表示するわけではありません John Doe:
仕方ありません
John 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/>";
私の結果;
Jane Doe =>
John Doe =>
=>こんにちは!
=>こんにちは、お元気ですか?
=>問題はありませんが、Facebook APIに問題があります
=>何が問題なのですか?
=>受信トレイのすべてのメッセージを一覧表示しない
=>どうしようもない
...bla
...bla
...bla
=>どうしようもない
h=>h
h=>h
すべてのメッセージと送信者名を表示したい。私がしようとしました;
1- 次の URL と file_get_content($url) を取得します。- 機能していません。
2- リミットとオフセットの割り当て - 機能しない
コードの書き方