Giter Club home page Giter Club logo

pgoapi-go's Introduction

pgoapi-go

Pokémon Go API tools written in Golang

Build Status

Source at: https://github.com/pogodevorg/pgoapi-go

Dependencies

Only supports Go 1.7

Library

You can include this package as a library in your own project.

Example

This is an example program that will retrieve player data and print it as JSON.

package main

import (
  "encoding/json"
  "fmt"
  "context"

  "github.com/pogodevorg/pgoapi-go/api"
  "github.com/pogodevorg/pgoapi-go/auth"
)

func main() {

  // Unless you already have another net/context complient context, use this empty context.
  // Read more about context at: https://godoc.org/context
  ctx := context.Background()

  // Initialize a new authentication provider to retrieve an access token
  provider, err := auth.NewProvider("ptc", "MyUser", "Pass1!!")
  if err != nil {
    fmt.Println(err)
    return
  }

  // Set the coordinates from where you're connecting
  location := &api.Location{
    Lon: 0.0,
    Lat: 0.0,
    Alt: 0.0,
    Accuracy: 3.0,
  }

  // Set up a feed to where all the responses will be pushed
  // The void feed will do nothing with the response entries
  feed := &api.VoidFeed{}

  // Set up the type of crypto to use for signing requests
  //
  // For most intents and purposes, you should be fine with
  // using the Default crypto.
  crypto := &api.DefaultCrypto{}

  // Start new session and connect
  session := api.NewSession(provider, location, feed, crypto, false)
  err = session.Init(ctx)
  if err != nil {
    fmt.Println(err)
    return
  }

  // Start querying the API
  player, err := session.GetPlayer(ctx)
  if err != nil {
    fmt.Println(err)
    return
  }

  out, err := json.Marshal(player)
  if err != nil {
    fmt.Println(err)
    return
  }

  fmt.Println(string(out))
}

Using the feed

The feed is a common interface to get a stream of all responses. This debug feed will print all wild pokemon and forts from map responses to standard out.

type DebugFeed struct {}

func (f *DebugFeed) Push(entry interface{}) {
  switch e := entry.(type) {
  default:
    // NOOP: Will not report type
  case *protos.GetMapObjectsResponse:
    cells := e.GetMapCells()
    for _, cell := range cells {
      pokemons := cell.GetWildPokemons()
      if len(pokemons) > 0 {
        fmt.Println(pokemons)
      }
      forts := cell.GetForts()
      if len(forts) > 0 {
        fmt.Println(forts)
      }
    }
  }
}

Command line tool

Install

Make sure you're running the latest version of Go, then simply install through go get.

$ go get -u github.com/pogodevorg/pgoapi-go

Usage

Get player profile

$ pgoapi-go -u <username> -p <Secret1234> --lat 0.0 --lon 0.0 player

Configure through environment variables

export PGOAPI_ACCOUNT_USERNAME=MyUserAccount
export PGOAPI_ACCOUNT_PASSWORD=PasswordThatIsSecret
$ pgoapi-go --lat 0.0 --lon 0.0 player

Credit

pgoapi-go's People

Contributors

akosterin avatar atuleu avatar femot avatar jroosing avatar keyphact avatar lisiano256 avatar mosasiru avatar novikk avatar segura2010 avatar ur0 avatar zeevallin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pgoapi-go's Issues

Are Pokemon being returned by the API?

I'm doing session.GetPlayerMap(ctx) and then iterating over the cells and calling GetWildPokemons() but nothing is being returned. Is anyone else having the same problem?

panic: Index out of range in api/session.go

Reproduction:

  1. Create new Session
  2. Initialize Session
  3. Call session.GetPlayerMap()

It seems that protos.ResponseEnvelope.Returns could at times be an empty slice?

Stacktrace:

panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x414ee0, 0xc82000a0b0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/pkmngo-odi/pogo/api.(*Session).GetPlayerMap(0xc820012550, 0x1, 0x0, 0x0)
    /Users/Moddy/go/src/github.com/pkmngo-odi/pogo/api/session.go:223 +0x47a
main.main()
    /Users/Moddy/go/src/github.com/moddyz/pokemapgo/test.go:49 +0x59b

Why no crypto solution?

Why is there no provided crypto solution? Other APIs have a provided crypto solution so I was just curious why this one doesn't.

Expose Session expiry time?

I was looking at the code in this repo https://github.com/AHAAAAAAA/PokemonGo-Map and it looks like there each provider has a expiry time that can be queried.
https://github.com/AHAAAAAAA/PokemonGo-Map/blob/master/pogom/pgoapi/pgoapi.py#L178
Upon expiry it looks like the client relogs in.

It looks like it's part of the AuthTicket struct:
https://github.com/pkmngo-odi/pogo-protos/blob/master/networking_envelopes.pb.go#L48

Could we possibly expose that on the session object so we know when to login again?

Do let me know if I'm not understanding Session properly :)

Still getting Index out of range error calling GetPlayerMap

Still getting the Index out of range error in sessions.go, when accessing one of the Returns slice at index 0

This is the exact code:

package main

import (
    "log"

    "golang.org/x/net/context"

    "github.com/pkmngo-odi/pogo/api"
    "github.com/pkmngo-odi/pogo/auth"
)

func main() {

    ctx := context.Background()

    provider, err := auth.NewProvider("ptc", "xqaYVxmzdVD8AjS", "EGi9tUf8cmIOq9a")
    if err != nil {
        log.Println(err)
        return
    }

    location := &api.Location{
        Lon: 0.0,
        Lat: 0.0,
        Alt: 0.0,
    }

    feed := &api.VoidFeed{}

    session := api.NewSession(provider, location, feed, false)
    err = session.Init(ctx)
    if err != nil {
        log.Println(err)
        return
    }

    _, err = session.GetPlayer(ctx)
    if err != nil {
        log.Println(err)
        return
    }

    _, err = session.GetPlayerMap(ctx)
    if err != nil {
        log.Println(err)
        return
    }

    _, err = session.Announce(ctx)
    if err != nil {
        log.Println(err)
        return
    }
}

The stacktrace:

Moddy:~/go/src/github.com/moddyz/pokemapgo$ go build -v . && ./pokemapgo
github.com/moddyz/pokemapgo
panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x417620, 0xc82000a0b0)
    /usr/local/go/src/runtime/panic.go:481 +0x3e6
github.com/pkmngo-odi/pogo/api.(*Session).GetPlayerMap(0xc820012640, 0x8951a0, 0xc82000a2a8, 0xc82042c2c0, 0x0, 0x0)
    /Users/Moddy/go/src/github.com/pkmngo-odi/pogo/api/session.go:230 +0x5e8
main.main()
    /Users/Moddy/go/src/github.com/moddyz/pokemapgo/main.go:43 +0x4c7

GetPlayerMap only get cell_id?

when I call GetPlayerMap() only get this return
{"map_cells":[{"s2_cell_id":6251754337001799680,"current_timestamp_ms":1472965820289},{"s2_cell_id":6251754343444250624,"current_timestamp_ms":1472965820289},{"s2_cell_id":6251754341296766976,"current_timestamp_ms":1472965820289},{"s2_cell_id":6251754332706832384,"current_timestamp_ms":1472965820289},{"s2_cell_id":6251754345591734272,"current_timestamp_ms":1472965820289}],"status":1}
is this right?

Panic: Index Out of Range calling GetPlayerMap()

I received the following error when calling GetPlayerMap():

panic: runtime error: index out of range

goroutine 59 [running]:
panic(0x757360, 0xc420010130)
/usr/lib/go/src/runtime/panic.go:500 +0x1a1
github.com/pogodevorg/pgoapi-go/api.(_Session).Announce(0xc42017c0a0, 0x987960, 0xc420010578, 0x7a6060, 0x474a01, 0xc4204eee40)
/home/steven/programming/go/src/github.com/pogodevorg/pgoapi-go/api/session.go:276 +0x800
github.com/pogodevorg/pgoapi-go/api.(_Session).GetPlayerMap(0xc42017c0a0, 0x987960, 0xc420010578, 0xc4203c9cd0, 0x2, 0x2)
/home/steven/programming/go/src/github.com/pogodevorg/pgoapi-go/api/session.go:307 +0x3f
mogo-go/process.(_Worker).Run.func1()
/home/steven/programming/go/src/mogo-go/process/worker.go:54 +0x150
mogo-go/process.(_Worker).Run.func1()
/home/steven/programming/go/src/mogo-go/process/worker.go:77 +0x3b2
created by mogo-go/process.(*Worker).Run
/home/steven/programming/go/src/mogo-go/process/worker.go:80 +0xca
exit status 2

It seems to come from err = proto.Unmarshal(response.Returns[5], mapObjects) in session.go. I'm not sure why it occurred but it only happened once after a couple of hours of testing. Perhaps we should check if the slice contains the required amount of elements before trying to access it?

Occasional "The profile needs to be authorized" error from session.GetPlayer() and session.getPlayerMap()

Reproduction (basically run the example code provided on README.md):

  1. Create new session with provider
  2. Init session
  3. Call either GetPlayer / GetPlayerMap or both

About half the time I'm getting the error "The profile needs to be authorized" returning from those method calls in 3.

The provider is definitely valid because the other half the time the call returns the player data / map data successfully.

Any ideas? Is there any more info I could provide?

Update to use new protobuffs?

It seems like the protobuffs have changed, I'm getting the following errors:

../github.com/pokeintel/pogo/api/session.go:147: cannot use requestHash (type []uint64) as type []int64 in field value
../github.com/pokeintel/pogo/api/session.go:148: cannot use locationHash1 (type uint32) as type uint64 in field value
../github.com/pokeintel/pogo/api/session.go:149: cannot use locationHash2 (type uint32) as type uint64 in field value
../github.com/pokeintel/pogo/api/session.go:150: unknown protos.Signature field 'Unknown22' in struct literal

Error when running "go get ...."

I am receiving the following error when attempting to run go get -u github.com/pokeintel/pogo

Cloning into 'POGOProtos'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
fatal: clone of '[email protected]:AeonLucid/POGOProtos.git' into submodule path 'POGOProtos' failed
package github.com/pokeintel/pogo-protos: exit status 128

This could well be something to do with my setup, but I thought I'd ask here in case anyone else is getting the same thing.

CellIds

Hey,

Don't know how else to come in contact, but what is the idea behind the cell ids? Do you create a grid on the map and then determine the location within the grid?

Really learning a lot from your code base, trying to find my place in doing actual contributions (just a beginner in golang).

Thanks for the inspiration anyway!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.