Skip to content

Instantly share code, notes, and snippets.

@ytera
Created November 16, 2015 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytera/c32306efdb213020414d to your computer and use it in GitHub Desktop.
Save ytera/c32306efdb213020414d to your computer and use it in GitHub Desktop.
twitteroathとphpを使って自分のタイムラインを表示するプログラム
<!-- 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