0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

特定のワードを拾って復唱し、そのユーザーをフォローするtwitter bot

0
Last updated at Posted at 2017-01-28

特定のワードのところは適当に変えて下さい
RTと@,#,リンクが含まれるツイートは無視しています。
起動はcronで。

twitterauthが必要です。
https://github.com/abraham/twitteroauth

$ composer require abraham/twitteroauth

<?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);
0
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?