Logo
Section 1 / 2

PRAW 简介

学习如何使用 Python 封装的 Reddit API。

导入

PRAW 简介

学习如何使用 Python 封装的 Reddit API。

参数类型必需性描述
user_agent字符串必需user_agent 用于标识网络请求的来源。我们需要一个唯一且具有描述性的 user_agent。
refresh_token字符串必需刷新令牌是一串字符,可用于获取经过身份验证的 Reddit 实例。
client_id字符串必需这是一串随机字符,用于用户身份验证。
client_secret字符串必需这是一串随机字符,用于用户身份验证。
1import praw 2 3reddit = praw.Reddit( 4 client_id="{{CLIENT_ID}}", 5 client_secret="{{CLIENT_SECRET}}", 6 refresh_token="{{REFRESH_TOKEN}}", 7 user_agent="testscript by u/{{USERNAME}}" 8) 9 10print(reddit.read_only)
1import praw 2import json 3 4reddit = praw.Reddit( 5 client_id="{{CLIENT_ID}}", 6 client_secret="{{CLIENT_SECRET}}", 7 refresh_token="{{REFRESH_TOKEN}}", 8 user_agent="testscript by u/{{USERNAME}}" 9) 10 11try: 12 response = reddit.user.preferences() 13 print(json.dumps(response, indent=4)) 14except Exception as e: 15 print(e)

与子版块互动

使用 PRAW 与帖子和评论进行交互