Lacro59 / playnite-successstory-plugin

This plugin shows the game achievements in Playnite.
https://playnite.link
MIT License
162 stars 29 forks source link

PSN API in 2.2.1 #176

Closed XenorPLxx closed 2 years ago

XenorPLxx commented 2 years ago

I've just seen the update for the SuccesStory, but it doesn't solve the problem for me - there's still no trophies.

There are two kinds of IDs in the PSN APIs - titleId (usually CUSAxxxxx_xx) and communicationId (usually NPWRxxxxxx_xx). All PS4 and PS5 games use titleId as Playnite's GameId, as it's the most universal one. Only PS3/PSP/PSVITA games use communicationId as GameId directly, as those don't have their titleId exposed.

private const string UrlAchievementsDetails = @"https://m.np.playstation.net/api/trophy/v1/npCommunicationIds/{0}/trophyGroups/all/trophies";
private const string UrlAchievements = @"https://m.np.playstation.net/api/trophy/v1/users/me/npCommunicationIds/{0}/trophyGroups/all/trophies";
(...)
Url = string.Format(UrlAchievements, GameId) + "?npServiceName=trophy";                 // all without ps5
UrlDetails = string.Format(UrlAchievementsDetails, GameId) + "?npServiceName=trophy";   // all without ps5

From your code, it seems that you are using the GameId directly for all games, which won't work for PS4 and PS5 games in the db. To get communicationId needed to retrieve trophies, you first need to retrieve it by translating titleId into communicationId by calling PsnAPI.GetTrohpiesWithIdsMobile, example use here: https://github.com/XenorPLxx/playnite-library-psn/blob/f430cb288444e36d3da8ff48d5564efbd9eda257/source/Libraries/PSNLibrary/PSNLibrary.cs#L267

Also, as the API takes 5 titleIds at a time, I'd suggest dumping it into a file instead of resolving it each time. PSN plugin does this only once to import 1.0 plugin games, so I didn't need to save it. There'll be some custom metadata fields in P10 that could be used to store communicationId.

Lacro59 commented 2 years ago

Can you try with this version? playnite-successstory-plugin_2_2_1.zip

I don't have any PS4 / PS5 games to check. So I made some assumptions about query results.

XenorPLxx commented 2 years ago

I've tried refreshing data on all my PSN games after updating the plugin, but no trophies showed up - I have over 200 PS4 & PS5 games.

image

You could try adding some free games to your library, like:

XenorPLxx commented 2 years ago
14-10 16:41:03.484|ERROR|SuccessStory#Common:Error on GetAchievements()|D:\GitHub\Lacro59\playnite-successstory-plugin\source\Clients\PSNAchievements.cs|84
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at CommonPluginsShared.Web.<DownloadStringData>d__12.MoveNext() in D:\GitHub\Lacro59\playnite-successstory-plugin\source\playnite-plugincommon\CommonPluginsShared\Web.cs:line 528
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at SuccessStory.Clients.PSNAchievements.GetAchievements(Game game) in D:\GitHub\Lacro59\playnite-successstory-plugin\source\Clients\PSNAchievements.cs:line 84

extensions.log

XenorPLxx commented 2 years ago

Per https://andshrew.github.io/PlayStation-Trophies/#/APIv2?id=obtaining-an-authentication-token

Invoke-RestMethod -Uri "https://m.np.playstation.net/api/trophy/v1/users/me/titles/trophyTitles?npTitleIds=PPSA01802_00" -Authentication Bearer -Token $token | ConvertTo-Json -Depth 6 | Out-File id-conversion.json
Invoke-RestMethod -Uri "https://m.np.playstation.net/api/trophy/v1/npCommunicationIds/NPWR21924_00/trophyGroups/all/trophies" -Authentication Bearer -Token $token | ConvertTo-Json -Depth 3 | Out-File trophy.json
Invoke-RestMethod -Uri "https://m.np.playstation.net/api/trophy/v1/users/me/trophyTitles" -Authentication Bearer -Token $token | ConvertTo-Json -Depth 3 | Out-File trophies.json

Results: apis.zip

Hope that helps :)

Lacro59 commented 2 years ago

Thanks for your help.

This version must be good: playnite-successstory-plugin_2_2_1.zip

XenorPLxx commented 2 years ago

Yes, it seems to be working fine now :). I'm seeing trophies for PS4 and PS5 games. Thanks for fixing this :).