【Python 】楽天APIを使用して転売ヤーより先に買う【導入#01】

楽天APIを叩いてみる

- YouTube
YouTube でお気に入りの動画や音楽を楽しみ、オリジナルのコンテンツをアップロードして友だちや家族、世界中の人たちと共有しましょう。

コード

import json
import os 
import requests

cur_dir = os.path.join(os.path.dirname(__file__))
parent_dir = os.path.dirname(cur_dir)
json_path = os.path.join(parent_dir , "config", "rakuten_api.json")
with open(json_path, "r", encoding="utf-8") as f:
    data = json.load(f)
    

API_ENDPOINT = "https://app.rakuten.co.jp/services/api/IchibaItem/Search/20170706"
API_KEY = data["AppID"]  # 楽天デベロッパーズで取得

params = {
    'applicationId': API_KEY,
    'keyword': 'Switch2',  # 検索ワード
    'hits': 10,              # 取得件数
    'format': 'json'
}

response = requests.get(API_ENDPOINT, params=params)
if response.status_code == 200:
    data = response.json()
    for item in data.get('Items', []):
        product = item['Item']
        print(f"商品名: {product['itemName']}")
        print(f"価格: {product['itemPrice']}円")
        print(f"URL: {product['itemUrl']}")
        print("----")
else:
    print("エラー:", response.status_code)

コメント