📌  相关文章
📜  Python PRAW – 与 redditor 交朋友

📅  最后修改于: 2022-05-13 01:54:37.935000             🧑  作者: Mango

Python PRAW – 与 redditor 交朋友

在 Reddit 中,redditor 是给予用户的术语。 Reddit 为我们提供了将 redditor 添加为经过身份验证的用户的朋友的功能。在这里,我们将看到如何与 redditor 成为朋友。我们将使用 Redditor 类的friend()方法与Redditor成为朋友。

朋友()

示例 1:考虑以下 redditor:

redditor的用户名是:spez

# importing the module
import praw
  
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
  
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id, 
                     client_secret = client_secret, 
                     username = username, 
                     password = password,
                     user_agent = user_agent) 
  
# the name of the redditor
redditor_name = "spez"
  
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
  
# before using the friend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))
  
# befriending the redditor
redditor.friend()
  
# after using the friend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))

输出 :

Are the authenticated user and spez friends? : False
Are the authenticated user and spez friends? : True

示例 2:考虑以下 redditor:

redditor 的用户名是:AutoModerator

# importing the module
import praw
  
# initialize with appropriate values
client_id = ""
client_secret = ""
username = ""
password = ""
user_agent = ""
  
# creating an authorized reddit instance
reddit = praw.Reddit(client_id = client_id, 
                     client_secret = client_secret, 
                     username = username, 
                     password = password,
                     user_agent = user_agent) 
  
# the name of the redditor
redditor_name = "AutoModerator"
  
# instantiating the Redditor class
redditor = reddit.redditor(redditor_name)
  
# before using the friend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))
  
# befriending the redditor
redditor.friend()
  
# after using the friend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))

输出 :

Are the authenticated user and AutoModerator friends? : False
Are the authenticated user and AutoModerator friends? : True