📌  相关文章
📜  Python PRAW – 取消与 redditor 的好友关系

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

Python PRAW – 取消与 redditor 的好友关系

在 Reddit 中,redditor 是给予用户的术语。 Reddit 为我们提供了将 redditor 添加为经过身份验证的用户的朋友的功能。我们也可以取消好友的好友。在这里,我们将看到如何取消与 redditor 的好友关系。我们将使用 Redditor 类的Redditor unfriend()方法取消与 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 unfriend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))
  
# unfriending the redditor
redditor.unfriend()
  
# after using the unfriend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))

输出 :

Are the authenticated user and spez friends? : True
Are the authenticated user and spez friends? : 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)
  
# before using the unfriend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))
  
# unfriending the redditor
redditor.unfriend()
  
# after using the unfriend() method
print("Are the authenticated user and " + redditor.name +
      " friends? : " + str(redditor.is_friend))

输出 :

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