2
2

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.

Twitterのトレンドを取得する

Posted at


import urllib
from requests_oauthlib import OAuth1
import requests
import sys

def main():

    # APIの秘密鍵
    CK = 'your key' # コンシューマーキー
    CKS = 'your key' # コンシューマーシークレット
    AT = 'your key' # アクセストークン
    ATS = 'your key' # アクセストークンシークレット

    tweets = get_trend(CK, CKS, AT, ATS,)

    # 検索結果を表示
    print(tweets[0:3])


def get_trend(CK, CKS, AT, ATS,):
    # リクエスト
    url = "https://api.twitter.com/1.1/trends/place.json?id=23424856"
    auth = OAuth1(CK, CKS, AT, ATS)
    response = requests.get(url, auth=auth)
    data = response.json()[0]['trends']

    return data


if __name__ == '__main__':
    main()
2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?