n
pip install PSNAWP
PyPI: https://pypi.org/project/PSNAWP/
อ่านเอกสาร: https://psnawp.readthedocs.io/en/latest/
คำเตือน
ไลบรารีนี้เป็น wrapper API ที่ไม่เป็นทางการและได้รับการออกแบบทางวิศวกรรมย้อนกลับสำหรับ PlayStation Network (PSN) ได้รับการพัฒนาโดยใช้วิศวกรรมย้อนกลับของแอป PSN Android API Wrapper (>= v2.1.0) จะจำกัดอัตราด้วยตนเองที่ 300 คำขอต่อ 15 นาที อย่างไรก็ตาม สิ่งสำคัญคือคุณต้องไม่ส่งคำขอจำนวนมากโดยใช้ 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 หลายอินสแตนซ์ คุณต้องได้รับรหัส npsso จากบัญชี PSN แยกต่างหาก หากคุณสร้าง npsso ใหม่ด้วยบัญชีเดียวกัน npsso ก่อนหน้าของคุณจะหมดอายุทันที
เรายินดีรับการโพสต์ข้อบกพร่องและคำขอคุณสมบัติทั้งหมด แม้ว่าฉันจะเป็นมือใหม่ในการสร้างไลบรารี่ Python ดังนั้นจึงอาจต้องใช้เวลาสักพักในการใช้งานคุณสมบัติบางอย่าง ยินดีรับข้อเสนอแนะหากฉันกำลังทำบางสิ่งที่เป็นวิธีที่แหวกแนวในการทำสิ่งนั้น
โครงการนี้ไม่ได้ตั้งใจเพื่อใช้สำหรับสแปม การละเมิด หรือสิ่งอื่นใด การใช้โครงการนี้เพื่อวัตถุประสงค์เหล่านั้นไม่ได้รับการรับรอง โปรดคำนึงถึงสิ่งนี้เมื่อสร้างแอปพลิเคชันโดยใช้ API Wrapper นี้
โปรเจ็กต์นี้มีโค้ดจาก PlayStationNetwork::API และ PSN-PHP Wrapper ที่แปลเป็น Python นอกจากนี้ ขอขอบคุณเป็นพิเศษ @andshrew สำหรับการบันทึกจุดสิ้นสุด PlayStation Trophy ใบอนุญาตทั้งหมดรวมอยู่ในพื้นที่เก็บข้อมูลนี้