SkyDrive へ移動![]()
twitteroauth のライブラリと 自作のコードも同梱されています。 twitter_post3.php
<?php
session_start();
require_once('twitteroauth/twitteroauth.php');
header( "Content-type: text/html; charset=utf-8");
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
$_SESSION['twitter_keys'] = $_POST['keys'];
$_POST['keys'] = str_replace("\r","",$_POST['keys']);
$_POST['keys'] = str_replace("\n","",$_POST['keys']);
$twitter_keys = explode(",", $_POST['keys'] );
$result = twitter_update(
$twitter_keys[0],
$twitter_keys[1],
$twitter_keys[2],
$twitter_keys[3],
$_POST['tpost']
);
$_SESSION['consumer_key'] = $twitter_keys[0];
$_SESSION['consumer_secret'] = $twitter_keys[1];
$_SESSION['access_token'] = $twitter_keys[2];
$_SESSION['access_token_secret'] = $twitter_keys[3];
print "<a href='twitter3.php?tpost=" . urlencode($_POST['tpost']) . "'>戻る</a>";
print "<pre>";
print_r(json_decode($result));
print "</pre>";
// *************************************************************************
// twitteroauth による処理
// *************************************************************************
function twitter_update( $apikey, $secret, $token, $token_secret, $text ) {
$oauth = new TwitterOAuth(
$apikey,
$secret,
$token,
$token_secret
);
$parameters = array( 'status' => $text );
$result = $oauth->oAuthRequest(
'https://api.twitter.com/1.1/statuses/update.json',
'POST',
$parameters
);
return $result;
}
?>
twitter3.php
<?php
session_start();
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link type="text/css" rel="stylesheet" href="client/style.css">
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="client/jquery.balloon.min.js"></script>
<script>
$(function() {
$('#twitter_keys').balloon(
{
position: "right",
tipSize: 20,
css: {
opacity: "1",
color: "#000",
fontSize: "16px",
borderRadius: "10px",
border: "solid 2px #A63814",
padding: "10px"
},
contents: 'この中に、カンマを区切りにして入力して下さい<br><br>'+
'一度投稿すると、セッションに保存されて、下部の赤枠内に表示されます<br>'
}
);
});
function check() {
}
</script>
</head>
<body>
<span style="color:#ff0000;font-weight:bold;"><?= $_GET['err'] ?></span>
<h2>Twitter 投稿</h2>
<pre>
<form
action="twitter_post3.php"
method="post"
onsubmit="return check();"
> このページでは、<a href="http://matome.naver.jp/odai/2135675108939679601" target="_blank">Consumer key,Consumer secret,Access token,Access token secret</a> を使って Twitter へ投稿します
<textarea name ="tpost" cols="100" rows="6"><?= $_GET['tpost'] ?></textarea>
<input type="submit"
name="submit"
value="投稿"
>
※ Consumer key,Consumer secret,Access token,Access token secret
<textarea name ="keys" cols="100" rows="5" id="twitter_keys"><?= $_SESSION['twitter_keys'] ?></textarea>
</form></pre>
<hr>
※ $_SESSION
<pre style='clear:left;font-size:20px;padding:20px;border:solid 2px #DE4600;margin-top:0px;'>
<?php
print_r($_SESSION);
?>
</pre>
</body>
</html>
関連する記事 abraham さんの twitteroauth のライセンスは、MIT ライセンスと同文
|
|
【PHP+通信の最新記事】
- PHP : curl で FTP サーバのファイル一覧( 結果は JSON )
- fake sendmail for windows ってなんで無名なんだ???
- Livedoor の お天気Webサービス API は、JSON のテストするのに重宝しています。
- PHP 5.2.0 以上で、サーバー間で FTPS( SSL 接続 )でファイル転送を行う
- abraham さんの twitteroauth の TwitterOAuth クラスのメソッド一覧概要
- abraham さんの twitteroauth のライセンスは、MIT ライセンスと同文
- PHPからのメール送信
- PHPによるFTPサーバーのデータ一括ダウンロード





























