-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtwitterBot.php
More file actions
27 lines (23 loc) · 906 Bytes
/
twitterBot.php
File metadata and controls
27 lines (23 loc) · 906 Bytes
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
<?php
require "vendor/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
define(CONSUMER_KEY, '');
define(CONSUMER_SECRET, '');
$access_token = '';
$access_token_secret = '';
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret);
$content = $connection->get("account/verify_credentials");
$tweet = $connection->get("search/tweets", array("q" => "薬 -RT -to:@* -#* -filter:links", 'count' => 1));
$id = $tweet->statuses[0]->user->id;
$rep = $tweet->statuses[0]->text;
$name = $tweet->statuses[0]->user->name;
$pos = strpos($rep,"@");
if($pos == 0) $rep = mb_substr($rep, strpos($rep," "));
if(empty($rep)) $rep = "No tweets found";
$statues = $connection->post("statuses/update", ["status" => $rep]);
$params = array(
'user_id' => $id,
//'screen_name'=>"",
'follow'=> 'true',
);
$addFriend = $connection->post("friendships/create", $params);