📜  Python PRAW - 检查redditor是否与用户成为朋友

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

Python PRAW - 检查redditor是否与用户成为朋友

在 Reddit 中,redditor 是给予用户的术语。 Reddit 允许经过身份验证的用户与另一个 redditor 成为“朋友”。在这里,我们将看到如何检查 redditor 是否与经过身份验证的用户成为朋友。我们将使用Redditor类的is_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)
  
print("Is " + redditor_name + " friends with the authenticated user? : " +
      str(redditor.is_friend))

输出 :

Is spez friends with the authenticated user? : False

示例 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)
  
print("Is " + redditor_name + " friends with the authenticated user? : " +
      str(redditor.is_friend))

输出 :

Is AutoModerator friends with the authenticated user? : False