Armax / Pokemon-GO-node-api

Pokemon GO api node.js library
MIT License
875 stars 198 forks source link

Something undefined #158

Closed necm1 closed 8 years ago

necm1 commented 8 years ago

EDIT

PokemonGO Servers down? :100:

Hello! I'm actually trying to create a simple web based Bot, and yeah. It's a little bit strange, I don't know what I did wrong. That's a part of my "class":

'use strict';

var PokemonGO = require('pokemon-go-node-api');

const Logger = require('./Core/Logger.js'); const log = new Logger();

function Instance(provider, username, password, location) { log.dif('Starting PokémonGO NodeJS Bot, written by Kylon...', 'yellow'); if(provider !== null && username !== null && password !== null) { if(location !== null && typeof location == 'object') { var instance = new PokemonGO.Pokeio(); log.info('Trying to connect & initialize user...'); instance.init(username, password, location, provider, (err) => { if(err) { log.error(err); }

    log.suc('Successfully logged in!');

    log.info('Current location: ' + instance.playerInfo.locationName);
    log.info('lat/long/alt: ' + instance.playerInfo.latitude + '/' + instance.playerInfo.longitude + '/' + instance.playerInfo.altitude);

    log.suc('Trying to get user profile');
    instance.GetProfile((err, profile) => {
      if(err) {
        log.error(err);
      }

      // Logging user infos
      log.dif('=========================', 'yellow');
      log.info('Username: ' + profile.username);

and that's what I'm getting in my console output:

[2016-07-27T16:36:28+02:00] Trying to connect & initialize user... [2016-07-27T16:36:29+02:00] Logging with user: xxx@gmail.com undefined [2016-07-27T16:36:29+02:00] Error: 403 error from server [2016-07-27T16:36:29+02:00] Successfully logged in! [2016-07-27T16:36:29+02:00] Current location: Times Square [2016-07-27T16:36:29+02:00] lat/long/alt: 40.759011/-73.9844722/0 [2016-07-27T16:36:29+02:00] Trying to get user profile

[2016-07-27T16:36:29+02:00] Error: Error

C:\Users\Frenk\Desktop\server\Instance.js:37 log.info('Username: ' + profile.username); ^

TypeError: Cannot read property 'username' of undefined at C:\Users\Frenk\Desktop\server\Instance.js:37:42 at C:\Users\Frenk\Desktop\server\node_modules\pokemon-go-node-api\poke.io.js:240:16 at Request._callback (C:\Users\Frenk\Desktop\server\node_modules\pokemon-go-node-api\poke.io.js:131:16) at self.callback (C:\Users\Frenk\Desktop\server\node_modules\request\request.js:187:22) at emitOne (events.js:77:13) at Request.emit (events.js:169:7) at Request.init (C:\Users\Frenk\Desktop\server\node_modules\request\request.js:233:17) at new Request (C:\Users\Frenk\Desktop\server\node_modules\request\request.js:129:8) at request (C:\Users\Frenk\Desktop\server\node_modules\request\index.js:55:10) at C:\Users\Frenk\Desktop\server\node_modules\request\index.js:63:12

and that's how I create the new instance:

var Instance = require('./Instance.js'); var pokemon = new Instance('google', 'mail', 'password', { type: 'name', name: process.env.PGO_LOCATION || 'Times Square' });

Why I'm getting 'undefined' and btw. what's undefined? The player object? Regards,

ALawliet commented 8 years ago

profile is undefined. Most likely from servers being down or unstable.

segura2010 commented 8 years ago

I recommend you use "return" to stop the execution if error occurred

if(err) {
return log.error(err);
}

or put the success block of code inside "else".

The error can be with server, they could be down. Other usual problem with Google login is the two factor authentication. If you have two factor authentication enabled, you can create an app password (https://support.google.com/mail/answer/185833?hl=en).

Also, I have developed a simple web bot/client (https://github.com/segura2010/NodeJS-PokemonGo-BotAndClient). It could help you to use the API or get ideas :) (sorry for the spam..)

necm1 commented 8 years ago

@ALawliet yeah.. I think they're down. @segura2010 Thank you very much. I'll take a look on your project.

I've no ideas what to do now. I'm still getting undefined. I don't know which variable is undefined. I think, I can't connect to the Google Auth Servers (not sure). I also getting 403 error from server (maybe wrong User-Agent?)..

I just get undefined... + 403 Server Error. But when I run Rocket C# Bot, everything works fine.

antonrez89 commented 8 years ago

Hey, does anybody know how to get user level?

necm1 commented 8 years ago

@Armax would be awesome, if you can close it. For people w/ the same problem: https://github.com/Armax/Pokemon-GO-node-api/issues/94