マイブーム@技術と生活

仕事や生活に関わる技術的なことを記述します。

Poke.io

参考:https://github.com/Armax/Pokemon-GO-node-api

ポケモンGO API node.js ライブラリ <開発中>

Discord に開発チャンネルがあります。開発でのみ使います。サポート問合せはしないでください。

example.js の例を確認してください。

 

インストール方法と使い方:

npm install pokemon-go-node-api
var Pokeio = require('pokemon-go-node-api')

 

マニュアル:

■ Pokeio.init(username, password, location, provider, callback)
ポケモントレーナークラブまたは Google アカウントで Pokeio を初期化する。地名または緯度・経度を指定できる。
username {String} ポケモントレーナークラブまたは Google アカウントのユーザー名
password {String} ポケモントレーナークラブまたは Google アカウントのパスワード
location {Object} 位置は、
  type = 'name' と name
  type = 'coords' と latitude、longitude、altitude
  の組合せで指定する
type {String} 'name' または 'coords'
name {String} Google マップ API を使い検索する地名
coords {Object}
  latitude {Number} 緯度
  longitude {Number} 経度
  altitude {Number} 標高
provider {String} 'ptc' または 'google'
callback {Function(error)}
  error {Error} エラー

■ Pokeio.GetAccessToken(username, password, callback)
Pokeio 内部変数に、接続チケットを保存する
username {String} ポケモントレーナークラブのユーザー名
password {String} ポケモントレーナークラブのパスワード
callback {Function(error, token)}
  error {Error} エラー
  token {String} チケット

■ Pokeio.GetApiEndpoint(callback)
Pokeio 内部変数に、API 終点を保存する
callback {Function(error, api_endpoint)}
error {Error} エラー
api_endpoint {String} API 終点

■ Pokeio.GetProfile(callback)
callback {Function(error, profile)}
error {Error} エラー
profile {Object} プロファイル
  creation_time {Number} 作成時間
  username {String} ユーザー名
  team {Number} チーム
  tutorial {Number/Boolean} 情報
    poke_storage {String} 所有できるポケモン
    item_storage {String} 所有できるアイテム数
    daily_bonus {Object} 毎日のボーナス
      NextCollectTimestampMs {Number} 次のアイテム入手更新時間(ms)
      NextDefenderBonusCollectTimestampMs {Number} 次の防衛ボーナス更新時間(ms)
    currency {Object} 所持金
      type {String} 種類
      amount {Number} 数量

■ Pokeio.GetLocation(callback)
Google マップ API を使い、現在の緯度・経度から、各国表記での住所を表示する
callback {Function(error, formattrd_address)}
error {Error} エラー
formatted_address {String} 各国表記での住所

■ Pokeio.GetLocationCoords()
Pokeio 内部変数に位置を保存する。緯度・経度または地名を指定できる
location {Object} 位置
  type {String} 'name' または 'coords'
  name {String} Google マップ API を使い検索する地名
  coords {Object}
    latitude {Number} 緯度
    longitude {Number} 経度
    altitude {Number} 標高
callback {Function(error, coordinates)}
error {Error} エラー
  coords {Object}
    latitude {Number} 緯度
    longitude {Number} 経度
    altitude {Number} 標高

 

プログラム例:

var a = new PokemonGO.Pokeio();
var location = {
 type: 'coords',
 coords: {
  'latitude': 35.712271,
  'longitude': 139.770557,
  'altitude': 0.0
 }
};

var username = 'abcde@gmail.com';
var password = 'xyz';
var provider = 'google';

a.init(username, password, location, provider, function(err) {
 if (err) throw err;

 console.log('1[i] Current location: ' + a.playerInfo.locationName);
 console.log('1[i] lat/long/alt: : ' + a.playerInfo.latitude + ' ' + a.playerInfo.longitude + ' ' + a.playerInfo.altitude);

 a.GetProfile(function(err, profile) {
  if (err) throw err;

  console.log('1[i] Username: ' + profile.username);
  console.log('1[i] Poke Storage: ' + profile.poke_storage);
  console.log('1[i] Item Storage: ' + profile.item_storage);

  var poke = 0;
  if (profile.currency[0].amount) {
   poke = profile.currency[0].amount;
  }

  console.log('1[i] Pokecoin: ' + poke);
  console.log('1[i] Stardust: ' + profile.currency[1].amount);

  setInterval(function(){
   a.Heartbeat(function(err,hb) {
   if(err) {
    console.log(err);
   }

   if(hb) {
    for (var i = hb.cells.length - 1; i >= 0; i--) {
     if(hb.cells[i].NearbyPokemon[0]) {
      var pokemon =  a.pokemonlist[parseInt(hb.cells[i].NearbyPokemon[0].PokedexNumber)-1];
      console.log('1[+] There is a ' + pokemon.name + ' near.');
     }
    }
   }
  });
  }, 5000);

 });
});

 

デモ:

node --debug-brk=28179 --nolazy example.js
Debugger listening on port 28179
[i] Logging with user: abcde@gmail.com
[i] Received Google access token!
[i] Received API Endpoint: https://pgorelease.nianticlabs.com/plfe/196/rpc
1[i] Current location: 2-1 Uenokōen, Taitō-ku, Tōkyō-to 110-0007, Japan
1[i] lat/long/alt: : 35.712271 139.770557 0
1[i] Username: abcde
1[i] Poke Storage: 250
1[i] Item Storage: 350
1[i] Pokecoin: 0
1[i] Stardust: 35247
[i] Logged in!
1[+] There is a Magikarp near.
1[+] There is a Psyduck near.
 

家で実験:

Github からプログラムコードを入手。[Clone or download]ボタンで Pokemon-GO-node-api-master.zip をダウンロード
cd C:\Git\Pokeio
npm install request
npm install geocoder
npm install protobufjs
npm install gpsoauthnode
npm install s2-geometry
npm install node-pogo-signature
npm install long

node example.js

 

日本語化:
pokemons.jsonポケモン名を日本語にしました。
https://1drv.ms/u/s!AtrmEyB9KEJijlh96gjw3mpSjoFX

 

プログラム例(ビュー):
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
  $.get(
    '/loc',
    function(data){
      $('#locationName').text(String(data));
    }
  );
  $.get(
    '/nearby',
    function(data){
      $('#nearbyPokemon').text(String(data));
    }
  );

  $('#set').click(function(){
    $.post(
      '/set',
      {latitude:$('#latitude').val(), longitude:$('#longitude').val()},
      function(data){
        $('#locationName').text(String(data));
        $('#nearbyPokemon').text('');
      }
    )
  });

  $('.map').click(function(){
    var id = $(this).attr('id');
    var data = id.split(',');
    $('#latitude').val(data[0]);
    $('#longitude').val(data[1]);
    $('#set').click();
  });

  setInterval(function() {
    $.get(
      '/loc',
      function(data){
        $('#locationName').text(String(data));
      }
    );
    $.get(
      '/nearby',
      function(data){
        $('#nearbyPokemon').text(String(data));
      }
    );
  }, 5000);
</script>

 

eexさんの情報(eextutto):
LEDのついた万歩計程度のもので、GOプラスに内蔵されてる振動センサーやら時計機能やらを元にポケモンが出現したことにして、アプリを立ち上げると位置に見合ったポケモンが出てきたことにすればいい

ポケストップからのアイテム入手は?
→ 近くを通ると自動的にアイテムを入手する。定期信号を送信して、スマホ側で位置ログを残せばよい

ダイアログ・セミコンダクター DA14580:「Pokemon GO Plus」のBLEソリューション、採用の決め手は