qlaffont / fortnite-api

Fortnite API, Get Stats, News And Status
https://twitter.com/qlaffont
MIT License
354 stars 86 forks source link

Please enter a good token - Goal : obtaining codes that work #114

Closed SteeledSlagle13 closed 6 years ago

SteeledSlagle13 commented 6 years ago

Hello, I know this issue has been resolve like 10 times already... I have looked at the Php repo and the other resolutions.. They all point me to the same Token and Client

Token : "MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y="
Client : "ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ="

I copied both from a previous issue in this repo and I also copied them from the Php repo

When I run my code :

// require the package
const Fortnite = require("fortnite-api");

let fortniteAPI = new Fortnite(
    [
        "****",
        "****",
        "MzRhMDJjZjhmNDQxNGUyOWIxNTkyMTg3NmRhMzZmOWE6ZGFhZmJjY2M3Mzc3NDUwMzlkZmZlNTNkOTRmYzc2Y2Y=",
        "ZWM2ODRiOGM2ODdmNDc5ZmFkZWEzY2IyYWQ4M2Y1YzY6ZTFmMzFjMjExZjI4NDEzMTg2MjYyZDM3YTEzZmM4NGQ="
    ],
    {
        debug: true
    }
);

fortniteAPI.login().then( function () {
    console.log('Hello');
});

Where **** is replaced with my login information(I have verified it is correct and I have toggle 2 factor Auth on and off).

When running this code I get :

Fortnite-API - Credentials Params OK
(node:7127) UnhandledPromiseRejectionWarning: Please enter good token
(node:7127) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7127) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

I have no idea what next step to take, so I am looking to anyone who sees this for advice.

KindaIntellectual commented 6 years ago

I was getting this error at one point too, unfortunately it was a while ago and I have since fixed/forgotten about them. 2-Auth should definitely be off. Could be the issue. Its not the actual login/credentials though as you get this

Fortnite-API - Credentials Params OK

I think it might be how you're passing info.

Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch().

I also kept getting that error along w/ the previous. First I'd try throwing a .catch() on the .login() so

fortniteAPI.login().then( function () { console.log('Hello'); }).catch(function(err){ console.log(err); }); Basically it just console logs the error (response/message) if there is one.

If that doesn't help, are you using Express/Router and/or an Ajax function? I feel like my issue was with how I tried to go about an ajax function, I had to place my function on .done() instead of success:

I'll try to look more into it tomorrow, hopefully any of the things I said above were helpful :) gl

jaysla2009 commented 6 years ago

I captured both tokens through fiddler and am having the same issue reported by @SteeledSlagle13 . Would really appreciate if you can share any resolutions you may find :)

SteeledSlagle13 commented 6 years ago

The error isn't with the info being passed. I tried adding a catch earlier but that didn't change anything other than the unhandled promise rejection.

Code :

fortniteAPI.login().then( function () {
    console.log('Hello');
}).catch(function (err) {
    console.log(err);
});

Generates :

Fortnite-API - Credentials Params OK
Please enter good token
KindaIntellectual commented 6 years ago

Well it was a theory but Not the info being passed. How that info is being passed.

BUT wait. Now it generates just "Please enter good token"?

Is the above code all that you're running? (Just to preface) I admit I am by no standards (especially my own) an expert or even "experienced" with git/apis. I still consider myself new to it all.

Looking back at my (horribly notated) commits, seems that I stopped getting the error when I moved my ajax post code from success, to done. Only non cosmetic change I noticed. Any additional code you are running would be helpful, I tried just running the code above, it does nothing but log you in and it does that successfully

If the above is the case, I think its asking in a not so upfront way, what now? You coded it to login, it did. Now it wants to do something so its asking you to send the "good token" aka the username + system (?)

But idk what else your code is doing after you login. But if you no longer get the other error its because you fixed the promise or async function that was being left undone, so to speak.

Additional code would be useful to truly get to the root of the issue.

If that is all you are running try running this

    fortniteAPI.login().then(function(){
        fortniteAPI.getStatsBR('wrekan', 'pc').then(function(stats){
            console.log(stats);
        }).catch(function(err){
                console.log(err);
            });
    });

This produces the Params OK log as well as outputs the info requested. I just filled it in with my fortnite info for example.

I tried re-producing your error but right now my code is sitting in a node/express app via router so idk which if not all of that is changing my output. But I can't get the "Please enter good token" to log

qlaffont commented 6 years ago

Before to declare your express Routing, you need to login on the API to be sure you will get all tokens you need.

SteeledSlagle13 commented 6 years ago

I have no idea what was going on with my code.... It works now. ¯_(ツ)_/¯ I feel like this is one of those instances of a meme I saw on reddit a while back 'It doesn't work... Why?' 12 hours later 'It works... Why?'

I literally just added :

fortniteAPI.getStatsBR('wrekan', 'pc').then(function(stats){
            console.log(stats);
        }).catch(function(err){
                console.log(err);
            });

into the login. Overall code with out the FortniteApi Object Declaration :

fortniteAPI.login().then(function () {
    fortniteAPI.getStatsBR('wrekan', 'pc').then(function (stats) {
        console.log(stats);
    }).catch(function (err) {
        console.log(err+' Inside function error');
    });
})
.catch(function (err) {
    console.log(err+' Outside function error');
});

I am so happy it is working now :D Thanks everyone I appreciate the help!

qlaffont commented 6 years ago

Good ! I will close this issue so ;) !