7
7

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 3 years have passed since last update.

インスタ自動いいねBOTを作る

Last updated at Posted at 2021-10-19

今回はGASを使ってサーバーレスでインスタいいねBOTを定期実行させます
GASは超初心者です

GASの使い方

こちらを参考にGASのプロジェクト作成してください

流れ

タグを選択

タグ検索

最新から10件の投稿IDを取得

いいね(10回ループ)

必要データ

①sessionid
②csrftoken

この2つが必要です
自分もよく分かっていませんが「ログイン時に割り当てられる個人ID」と「アカウントを操作するのに必要なトークン」だと勝手に思っています

これらはデベロッパーツールから確認することができます

必要データの取得方法

①自分のインスタアカウントにログインする
②デベロッパーツールを開く(開き方が分からない場合ググってください)
スクリーンショット 2021-10-19 13.04.57.png

使用API

検索
https://www.instagram.com/explore/tags/検索ワード/?__a=1

いいね
https://www.instagram.com/web/likes/投稿ID/like/

ソースコード

var headers = {
        "cookie":"sessionid=ここに自身のsessionid;",
    "x-csrftoken":"ここに自身のx-csrftoken"
};

function SELECT_TAG() {
  try {
    var tags = [
      "like4like",
      "l4l",
      "follow4follow",
      "f4f",
      "tflers",
      "%EC%A2%8B%EC%95%84%EC%9A%94%EB%B0%98%EC%82%AC",
      "%E3%81%84%E3%81%84%E3%81%AD%E8%BF%94%E3%81%97"
    ];
    var tag = tags[Math.floor(Math.random()*tags.length)];
    return tag;
  } catch(error) {
    console.log("SELECT_TAGでエラー発生")
  };
};

function GET_ID_LIST() {
  try {
    var tag = SELECT_TAG();
    var url = "https://www.instagram.com/explore/tags/" + tag + "/?__a=1";
    var options = {
      "method" : "get",
      "headers" : headers
    };
    var reply = UrlFetchApp.fetch(url, options);
    var json = JSON.parse(reply);
    var data = json["data"]["recent"]["sections"];
    var ID_LIST = [];
    for(var i=0; i<data.length; i++) {
      var id_num = data[i]["layout_content"]["medias"][0]["media"]["id"]
      var id = id_num.slice(0,id_num.indexOf("_"))
      ID_LIST.push(id);
    };
    return ID_LIST;
  } catch(error) {
    console.log("GET_ID_LISTでエラー発生")
  };
};

function Create_Favorite() {
  try {
    var ID_LIST = GET_ID_LIST();
    for (var i in ID_LIST) {
      var url = "https://www.instagram.com/web/likes/" + ID_LIST[i] + "/like/";
      var options = {
        "method" : "post",
        "headers" : headers
      };
      var ResponseCode = UrlFetchApp.fetch(url, options).getResponseCode();
      console.log(ResponseCode);
    };
  } catch(error) {
    console.log("Create_Favoriteでエラー発生");
  };
};

あとはトリガーを設定するだけで定期実行してくれます

え、、GASって神...??

7
7
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
7
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?