Tustin / psn-php

A PHP wrapper for the PSN API
https://tustin.dev/psn-php/
MIT License
356 stars 73 forks source link

[V3] Where to start with master-branch ? #176

Closed Reuns closed 2 years ago

Reuns commented 3 years ago

Hello. I was using V2.1.3 before it stopped. Now I've downloaded the master-branch but I don't know where to start.

I'm a bit lost (completely actually) and without any doc I can't do anything :( Can someone provide me some help please ?

I'm stuck at the very beginning. Thanks.

isFakeAccount commented 3 years ago

You can use my version of PSN API https://github.com/isFakeAccount/psnawp. Since it is in python it should be easy to use.

The authentication work as of now. There is an issue with messaging endpoints. But if you are not using them, you should be fine.

Unfortunately, Tustin is MIA as of now due to workload,

Reuns commented 3 years ago

You can use my version of PSN API https://github.com/isFakeAccount/psnawp. Since it is in python it should be easy to use.

Thank you for your help but I need a php version.

Ragowit commented 3 years ago
require_once("/path/to/vendor/autoload.php");

use Tustin\PlayStation\Client;

$client = new Client();
$client->loginWithNpsso("your npsso");

foreach ($client->users()->search("Reuns") as $user) {
    foreach ($user->trophyTitles() as $trophyTitle) {
    }
}
Reuns commented 3 years ago

Ok, just that simple (i feel ashamed). Thank you @Ragowit

How does the refreshToken works on this version ? I tried to save $client->getRefreshToken()->getToken () And use it like $client->loginWithRefreshToken ($mypreviouslysavedtoken) but it doesn't seems to work ... Fatal Error

Fatal error: Uncaught Tustin\Haste\Exception\ApiException in /[...]/vendor/tustin/haste/src/Http/Middleware/ResponseHandlerMiddleware.php:57 Stack trace: #0 /[...]/vendor/tustin/haste/src/Http/Middleware/ResponseHandlerMiddleware.php(32): Tustin\Haste\Http\Middleware\ResponseHandlerMiddleware->handleErrorResponse(Object(GuzzleHttp\Psr7\Response), Object(Tustin\Haste\Http\JsonStream)) #1 /[...]/vendor/guzzlehttp/promises/src/FulfilledPromise.php(41): Tustin\Haste\Http\Middleware\ResponseHandlerMiddleware->__invoke(Object(GuzzleHttp\Psr7\Response)) #2 /[...]/vendor/guzzlehttp/promises/src/TaskQueue.php(48): GuzzleHttp\Promise\FulfilledPromise::GuzzleHttp\Promise{closure}() #3 /[...]/vendor/guzzlehttp/promises/src/Promise.php(248): GuzzleHttp\Promise\TaskQueue->run(true) #4 /home/brre5190/publ in /[...]/vendor/tustin/haste/src/Http/Middleware/ResponseHandlerMiddleware.php on line 57

Ragowit commented 3 years ago

The refreshToken doesn't work at all afaik. Don't think it's a thing anymore with the new API. Remember that the master-branch is under development and some stuff in there might just be legacy code that is meant to be removed at some point, and I believe refreshToken is one of those things.

I just use loginWithNpsso all the time within my code. It usually lasts for about two months before I need to update the npsso. I've tried to have a second dummy account as backup if the first one fails to login, but it seems that if one of my npsso needs to be refreshed, all my npsso needs to be refreshed. It's like Sony uses a button that forces a new npsso token on all users at certain intervals.

Reuns commented 3 years ago

Ok, good to know. I guess I'll have to keep an eye on this npsso ;)

I'll try to find my way with the code. Thanks again, I hope I won't have to bother you again.

See ya. ;)

Tustin commented 3 years ago

@Reuns Sorry about this. The new API is quite a bit of a different beast and I've yet to sit down and write documentation for it. If there's anything in particular you need help porting over, please let me know and I can try to help 😄

Tustin commented 3 years ago

@Reuns I just fixed the loginWithRefreshToken method in 450ec04b42b4859d2042c3eb7f9ce8b511eafa5c. Please try it again 👍

$client->loginWithRefreshToken('5d37cd0e-4d33-xxxx-afb2-xxxxxxxxxx');

var_dump($client->getAccessToken()->getToken());
jeroenbourgois commented 3 years ago

@Tustin did you have any luck finding the old 'gamelist' endpoint yet? I have been searching and trying a lot of endpoints, also trying to reverse-engineer the Android app, but no luck. Trophies are accessible, but game info I have no idea.

quangtn commented 3 years ago

i've been using kvickpsn, it worked great so far until about a month ago. Endpoints for 'threads' stop working and always return rate limit error. It'd be great if anyone share some insight on that.

Reuns commented 3 years ago

Hey, back on track ! For real this time... Thanks @Tustin, login with token works great.

Why do I have <b>Fatal error</b>: Uncaught Tustin\Haste\Exception\AccessDeniedHttpException in /home/brre5190/public_html/scoring.high-score.fr/core/vendor/tustin/haste/src/Http/Middleware/ResponseHandlerMiddleware.php:61

I'm not good with the try / catch thing. this is what i've tried

$user = $client->users()->find($accountId); try { $user->trophySummary ()->fetch (); } catch (AccessDeniedHttpException $e) { echo $e->getMessage (); } But still ... I have the same message. Is there something I'm doing wrong ? Thanks.

Argosth commented 3 years ago

Hey, back on track ! For real this time... Thanks @Tustin, login with token works great.

Why do I have <b>Fatal error</b>: Uncaught Tustin\Haste\Exception\AccessDeniedHttpException in /home/brre5190/public_html/scoring.high-score.fr/core/vendor/tustin/haste/src/Http/Middleware/ResponseHandlerMiddleware.php:61

I'm not good with the try / catch thing. this is what i've tried

$user = $client->users()->find($accountId); try { $user->trophySummary ()->fetch (); } catch (AccessDeniedHttpException $e) { echo $e->getMessage (); } But still ... I have the same message. Is there something I'm doing wrong ? Thanks.

Hello Reuns, did you manage to solve that exception? I'm still doing this:

require_once '../vendor/autoload.php'; use Tustin\PlayStation\Client; $client = new Client(); / First Login / $client->loginWithNpsso('Npsso-Code'); $refreshToken = $client->getRefreshToken()->getToken();

// Your games foreach ($client->users()->search("Argosth") as $user) { foreach ($user->trophyTitles() as $trophyTitle) {

}

}

But still getting the error: Fatal error: Uncaught Tustin\Haste\Exception\AccessDeniedHttpException in C:\xampp\htdocs\Argosth\vendor\tustin\haste\src\Http\Middleware\ResponseHandlerMiddleware.php:61 Stack trace: #0

Any ideas?

Thank you :)

Reuns commented 3 years ago

Hi @Argosth

I don't have any error at this point. $client->users()->find($accountId)->trophyTitles() works great.

Can you share us more of your code ?

Argosth commented 3 years ago

Hi @Argosth

I don't have any error at this point. $client->users()->find($accountId)->trophyTitles() works great.

Can you share us more of your code ?

Hello, thank you, here is all my steps until now:

My composer version is:

guzzlehttp/guzzle 7.3.0 Guzzle is a PHP HTTP client library guzzlehttp/promises 1.4.1 Guzzle promises library guzzlehttp/psr7 2.0.0 PSR-7 message implementation that also provides common utility me... myclabs/php-enum 1.7.7 PHP Enum implementation nesbot/carbon 2.53.1 An API extension for DateTime that supports 281 different languages. psr/http-client 1.0.1 Common interface for HTTP clients psr/http-factory 1.0.1 Common interfaces for PSR-7 HTTP message factories psr/http-message 1.0.1 Common interface for HTTP messages ralouphie/getallheaders 3.0.3 A polyfill for getallheaders. symfony/deprecation-contracts v2.4.0 A generic function and convention to trigger deprecation notices symfony/polyfill-mbstring v1.23.1 Symfony polyfill for the Mbstring extension symfony/polyfill-php80 v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP ... symfony/translation v5.3.7 Provides tools to internationalize your application symfony/translation-contracts v2.4.0 Generic abstractions related to translation tustin/haste v1.0.6 HTTP library for my API library projects tustin/psn-php dev-master 3dcfc62 PHP wrapper for the PlayStation API.

I think, I have the dev psn-api, because I modified the composer.json with the next code and used composer update: { "require": { "tustin/psn-php": "dev-master" } }

Now, I used the next method to log in with npsso:

require_once '../vendor/autoload.php'; use Tustin\PlayStation\Client; $client = new Client(); /* First Login */ $client->loginWithNpsso('my-code'); $refreshToken = $client->getRefreshToken()->getToken();

After that, I call the functions with the next code:

foreach ($client->users()->search("Argosth") as $user) { foreach ($user->trophyTitles() as $trophyTitle) {

} }

At this moment is when the error appears, any ideas?

Reuns commented 3 years ago

I can't see what's wrong with your code. Have you tried to catch the exception ?

Argosth commented 3 years ago

I can't see what's wrong with your code. Have you tried to catch the exception ?

No Reuns, how can I try/catch that exception inside a loop?

Reuns commented 3 years ago

Sorry, I can't help you, My skills are limited...

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.