n
pip install PSNAWP
PyPI:https://pypi.org/project/PSNAWP/
阅读文档:https://psnawp.readthedocs.io/en/latest/
警告
该库是 PlayStation Network (PSN) 的非官方和逆向工程 API 包装器。它是基于PSN Android应用程序的逆向工程开发的。 API 包装器 (>= v2.1.0) 将自我速率限制为每 15 分钟 300 个请求。但是,不要使用此 API 发送批量请求,这一点仍然很重要。过度使用 API 可能会导致您的 PSN 帐户被暂时或永久禁止。
您还可以创建一个专用帐户来使用该库,这样在最坏的情况下您也不会失去对主帐户以及视频游戏和进度的访问权限。
首先,您需要获取 npsso <64 字符代码>。您需要按照以下步骤操作
https://ca.account.sony.com/api/v1/ssocookie
{ "npsso" : " <64 character npsso code> " }
此 npsso 代码将在 api 中用于身份验证目的。从 npsso 生成的刷新令牌持续约 2 个月。之后,您必须获得新的 npsso 令牌。如果刷新令牌到期时间还剩不到 3 天,机器人将打印一条警告。
以下是有关如何使用该库的快速示例
from psnawp_api import PSNAWP
from psnawp_api . models import SearchDomain
from psnawp_api . models . trophies import PlatformType
psnawp = PSNAWP ( "<64 character npsso code>" )
# Your Personal Account Info
client = psnawp . me ()
print ( f"Online ID: { client . online_id } " )
print ( f"Account ID: { client . account_id } " )
print ( f"Profile: { client . get_profile_legacy () } n " )
# Your Registered Devices
devices = client . get_account_devices ()
for device in devices :
print ( f"Device: { device } n " )
# Your Friends List
friends_list = client . friends_list ()
for friend in friends_list :
print ( f"Friend: { friend } n " )
# Your Players Blocked List
blocked_list = client . blocked_list ()
for blocked_user in blocked_list :
print ( f"Blocked User: { blocked_user } n " )
# Your Friends in "Notify when available" List
available_to_play = client . available_to_play ()
for user in available_to_play :
print ( f"Available to Play: { user } n " )
# Your trophies (PS4)
for trophy in client . trophies ( "NPWR22810_00" , PlatformType . PS4 ):
print ( trophy )
# Your Chat Groups
groups = client . get_groups ()
first_group_id = None # This will be used later to test group methods
for id , group in enumerate ( groups ):
if id == 0 : # Get the first group ID
first_group_id = group . group_id
group_info = group . get_group_information ()
print ( f"Group { id } : { group_info } n " )
# Your Playing time (PS4, PS5 above only)
titles_with_stats = client . title_stats ()
for title in titles_with_stats :
print (
f"
Game: { title . name } -
Play Count: { title . play_count } -
Play Duration: { title . play_duration } n "
)
# Other User's
example_user_1 = psnawp . user ( online_id = "VaultTec-Co" ) # Get a PSN player by their Online ID
print ( f"User 1 Online ID: { example_user_1 . online_id } " )
print ( f"User 1 Account ID: { example_user_1 . account_id } " )
print ( example_user_1 . profile ())
print ( example_user_1 . prev_online_id )
print ( example_user_1 . get_presence ())
print ( example_user_1 . friendship ())
print ( example_user_1 . is_blocked ())
# Example of getting a user by their account ID
user_account_id = psnawp . user ( account_id = "9122947611907501295" )
print ( f"User Account ID: { user_account_id . online_id } " )
# Messaging and Groups Interaction
group = psnawp . group ( group_id = first_group_id ) # This is the first group ID we got earlier - i.e. the first group in your groups list
print ( group . get_group_information ())
print ( group . get_conversation ( 10 )) # Get the last 10 messages in the group
print ( group . send_message ( "Hello World" ))
print ( group . change_name ( "API Testing 3" ))
# print(group.leave_group()) # Uncomment to leave the group
# Create a new group with other users - i.e. 'VaultTec-Co' and 'test'
example_user_2 = psnawp . user ( online_id = "test" )
new_group = psnawp . group ( users_list = [ example_user_1 , example_user_2 ])
print ( new_group . get_group_information ())
# You can use the same above methods to interact with the new group - i.e. send messages, change name, etc.
# Searching for Game Titles
search = psnawp . search ( search_query = "GTA 5" , search_domain = SearchDomain . FULL_GAMES )
for search_result in search :
print ( search_result [ "result" ][ "invariantName" ])
注意:如果您想创建 psnawp 的多个实例,您需要从单独的 PSN 帐户获取 npsso 代码。如果您使用同一帐户生成新的 npsso,您之前的 npsso 将立即过期。
欢迎所有错误转发和功能请求,尽管我是制作 python 库的新手,所以可能需要一段时间才能实现某些功能。如果我正在做一些非常规方式的事情,欢迎提出建议。
该项目无意用于垃圾邮件、滥用或任何此类行为。不认可将本项目用于这些目的。使用此 API 包装器创建应用程序时请记住这一点。
该项目包含来自 PlayStationNetwork::API 和 PSN-PHP Wrapper 的代码,并已翻译为 Python。另外,特别感谢 @andshrew 记录 PlayStation Trophy 端点。所有许可证都包含在此存储库中。