Skip to content

Instantly share code, notes, and snippets.

@howyi
Created July 16, 2015 05:23
Show Gist options
  • Save howyi/a76bf1ba075d30361080 to your computer and use it in GitHub Desktop.
Save howyi/a76bf1ba075d30361080 to your computer and use it in GitHub Desktop.
Tweet
<html>
<head>
<title>Tweet</title>
</head>
<body>
<pre>
<?php
session_start();
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
require "initialize.php";
#APIにアクセスするためのアクセストークンを用いて$connectionを作成
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET,
$_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
#"Hello,world!"とツイートする、$resultにはbool型で実行結果が出力される
$result = $connection->post('statuses/update', array('status' => "Hello,world!"));
if($result){
print ("success!");
}else{
print ("failed...");
}
#ログインしたアカウントのプロフィールの取得、出力
var_dump($connection->get("account/verify_credentials"));
?>
</pre>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment