-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathajax_query.php
71 lines (68 loc) · 3.05 KB
/
ajax_query.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
require_once 'lib/TwistOAuth.phar';
require_once 'config.php';
require_once 'token.php';
session_start();
$to = $_SESSION['to'];
try {
if ($_GET['method'] == "more") {
//=========================================================
//過去ツイート読み込み時
//=========================================================
$timeline = $to->get('statuses/home_timeline',array('max_id' => $_GET['max_id'],'count' => 200));
}else if($_GET['method'] == "ready"){
//=========================================================
//初回読み込み時
//=========================================================
$timeline = $to->get('statuses/home_timeline',array('count' => 120));
}else{
//=========================================================
//最新ツイート読み込み時
//=========================================================
$timeline = $to->get('statuses/home_timeline',array('since_id' => $_GET['min_id'],'count' => 40));
}
// レスポンス確認(異常時にはcatchにジャンプするため、ここへの到達は成功を意味する)
foreach($timeline as $i => $tweet){
if(isset($_GET['max_id']) && $i == 0){
continue;
}
if (isset($tweet->extended_entities->media[0]->media_url)) {
foreach ($tweet->extended_entities->media as $key => $value) {
if (!isset($tweet->retweeted_status)){
$screen_name = $tweet->user->screen_name;
$id_bigint = $tweet->user->id;
$profile_image_url = $tweet->user->profile_image_url;
$name = $tweet->user->name;
}else{
$screen_name = $tweet->retweeted_status->user->screen_name;
$id_bigint = $tweet->retweeted_status->user->id;
$profile_image_url = $tweet->retweeted_status->user->profile_image_url;
$name = $tweet->retweeted_status->user->name;
}
echo '
<div class="box" id="'.$tweet->id_str.'">
<img src="'.$value->media_url.':orig" width="320px">
<div class="tweet-text">
<div class="media">
<div class="media-left media-middle">
<a href="'."https://twitter.com/".$screen_name.'">
<img class="media-object" width="32px" src="'.$profile_image_url.'">
</a>
</div>
<div class="media-body">
<b>'.h($name).'</b>
<br>
'.h($tweet->text).'
</div>
</div>
</div>
</div>
';
}
}
}
} catch (TwistException $e) {
// エラーを表示
header("HTTP/1.1 500 Internal Server Error");
exit;
}