見出し画像

(AI問答)TwitterAPIを使い、自分のフォローしているユーザー達を、最終ツイートの古い順で並び替えて出力してくれるGoogleコラボアプリはあるか?


1.BingAI(Copilot)

Twitter APIを使用して、フォローしているユーザーを最終ツイートの古い順に並び替えるGoogle Colabアプリについては、直接的な情報は見つかりませんでしたが、Twitter APIを利用してこのような機能を実装することは可能です。以下はPythonを使用してTwitter APIでフォローしているユーザーを最終ツイートの日時で並び替えるサンプルコードです。このコードをGoogle Colabで実行することができます。

import tweepy
import pandas as pd

# 認証に必要なキーとトークン
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
access_token = 'YOUR_ACCESS_TOKEN'
access_token_secret = 'YOUR_ACCESS_TOKEN_SECRET'

# 認証を行う
auth = tweepy.OAuthHandler(api_key, api_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)

# 自分のフォローしているユーザーのIDを取得
following_ids = api.get_friend_ids()

# ユーザーの詳細と最終ツイートの日時を取得
users = []
for user_id in following_ids:
    user = api.get_user(user_id=user_id)
    users.append({
        'id': user_id,
        'screen_name': user.screen_name,
        'last_tweet_date': user.status.created_at if hasattr(user, 'status') else None
    })

# DataFrameを作成
df = pd.DataFrame(users)

# 最終ツイートの日時で並び替え
df_sorted = df.sort_values(by='last_tweet_date', ascending=True)

# 結果を出力
print(df_sorted)

このコードは、あなたのTwitterアカウントで認証を行い、フォローしているユーザーのIDを取得し、それぞれのユーザーの最終ツイートの日時を取得して、古い順に並び替えて出力します。`YOUR_API_KEY`、`YOUR_API_SECRET`、`YOUR_ACCESS_TOKEN`、`YOUR_ACCESS_TOKEN_SECRET`には、あなたのTwitter Developerアカウントから取得した対応する値を入力してください。

なお、Twitter APIの利用にはTwitter Developerアカウントが必要で、適切な権限を持ったAPIキーとアクセストークンが必要です。また、APIの利用制限に注意しながら使用してください。3

ソース: Bing との会話 2024/3/14
(1) 【2023年度最新版】Twitter API 取得方法 - Zenn. https://zenn.dev/eito_blog/articles/a982fdb073493a.
(2) undefined. https://www.rakuten.ne.jp/gold/aste/note/100topic_009.html.
(3) Twitterのフォロワー一覧で表示される順番を並び替える方法や .... https://kamitter.tokyo/blog/how-to-twitter/twitter-auto-follow-sorting-change-tool/.
(4) 並べ替え | Docs | Twitter Developer Platform. https://developer.twitter.com/ja/docs/twitter-ads-api/sorting.
(5) 【Twitter API v2の使い方】フォロー・フォロー解除を実行する .... https://itosaru.com/twitter-api-follow-and-unfollow/.

結論

無料枠で試せるかどうか?
それが問題だ

この記事が参加している募集

仕事について話そう

ビットコイン普及して欲しいですね