-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitter-bot.php
More file actions
40 lines (35 loc) · 1.08 KB
/
twitter-bot.php
File metadata and controls
40 lines (35 loc) · 1.08 KB
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
<?php
// OAuthスクリプトの読み込み
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
require_once 'config.php';
// Consumer key
$consumer_key = API_KEY;
// Consumer secret
$consumer_secret = API_SECRET;
// Access token
$access_token = ACCESS_TOKEN;
// Access token secret
$access_token_secret = ACCESS_SECRET;
// おまじない
$header = 'Content-Type: text/plain; charset=utf-8';
// つぶやく
try {
// TwistOAuthの新しい接続を生成
$connection = new TwitterOAuth($consumer_key, $consumer_secret, $access_token, $access_token_secret);
// ツイートする
$res = $connection->post('statuses/update', [
'status' => 'Hello!!!'
]);
// おまじない
header($header, true, 200);
// 返却値。成功したら、「ツイートしました。」とブラウザに表示
echo "ツイートしました";
var_dump($res);
} catch (Exception $e) {
// おまじない
header($header, true, $e->getCode() ?: 500);
// ツイートに失敗したら、「ツイート失敗」と表示
echo "ツイート失敗: {$e->getMessage()}\n";
}
?>