Created
November 16, 2015 08:55
-
-
Save ytera/c32306efdb213020414d to your computer and use it in GitHub Desktop.
twitteroathとphpを使って自分のタイムラインを表示するプログラム
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- phpで準備 --> | |
<?php | |
require_once("twitteroauth/autoload.php"); | |
use Abraham\TwitterOAuth\TwitterOAuth; | |
function h($str, $double = true){ | |
return htmlspecialchars($str, ENT_QUOTES, 'UTF-8', $double); | |
} | |
date_default_timezone_set('Asia/Tokyo'); | |
$consumer_key = 'コンシューマーキー'; | |
$consumer_secret = 'コンシューマーシークレット'; | |
$access_token = 'アクセストークン'; | |
$access_token_secret = 'アクセストークンシークレット'; | |
$toa = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret); | |
$statuses = $toa->get('statuses/home_timeline', ['count' => '20']); | |
header('Content-Type: text/html; charset=utf-8'); | |
?> | |
<!-- htmlでページ構成 --> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>PHP Twitter test</title> | |
</head> | |
<body> | |
<?php foreach ($statuses as $status): ?> | |
<hr/> | |
<ul> | |
<li>name --- <?=h($status->user->name)?></li> | |
<li>screen_name --- @<?=$status->user->screen_name?></li> | |
<li>location --- <?=h($status->user->location)?></li> | |
<li>description --- <?=h($status->user->description)?></li> | |
<li>date --- <?=date('Y/m/d H:i:s', strtotime($status->created_at))?></li> | |
<li>false --- <?=h($status->text, false)?></li> | |
<li>image --- <img src="<?php echo $status->user->profile_image_url;?>"></li> | |
</ul> | |
<?php endforeach;?> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment