nabeelamjad / poke-api Goto Github PK
View Code? Open in Web Editor NEWPoke API - A Ruby API gem for Pokémon GO.
License: MIT License
Poke API - A Ruby API gem for Pokémon GO.
License: MIT License
@nabeelamjad
The S2 geometry cells which are natively implemented in ruby will be very helpful in my project. The Lat-Long to cell id conversion code is ported from the S2 Geometry library. But the cell id to lat-long conversion is not available in this gem.
Can you help me to port the rest of the library? And guide me with the required resources for porting the library?
Hi,
is store_location needed? It's in all your examples but I am just wondering if it is required/expected or if I can simply skip it?
Thanks!!
I am trying to understand this (https://github.com/nabeelamjad/poke-api/blob/master/lib/poke-api/auth/ptc.rb):
def fetch_ticket(data)
logger.debug '[>] Fetching PTC ticket'
ticket = begin
@client.post_content(PTC_LOGIN_URL, data)
rescue StandardError => ex
ex.res.http_header.request_uri.to_s.match(/ticket=(.*)/)[1]
end
fetch_access_token(ticket)
end
I'm tried running the code individually. It seems httpclient
lib fails unexpectedly, thats why you need the begin
block there. The ticket
is used to generate the access token on the next method.
Doing the same thing on httparty
(another http gem), doesnt render any errors:
Take for example:
JSON.parse(
HTTParty.post(
ptc_login_url,
headers: {
'agent_name' => 'PokeAPI/0.0.1'
},
body: {
data: {
username: 'some_username',
password: 'password',
_eventId: 'submit',
lt: json_response['lt'],
execution: json_response['execution']
}
}
)
)
However, the response I get instead is {"lt"=>"LT-23868518-ohkebxUhorQIFc11V3441qrSMOhFdF", "execution"=>"e1s1"}
Instead of what you currently need for the ticket: ST-7486015-NGPOWEQLoxc2mJM4flun-sso.pokemon.com
Am I missing something with the HTTParty approach?
Hi @nabeelamjad, any idea what Poke::API::Errors::ForbiddenAccess - Your host is unable to receive a response as it is banned.
means/how it can be fixed?
There is no way to get the status_code
of a response or the error
string because the response given only includes the subresponses
Can you please update the signature proto to reflect the updates in this commit: AeonLucid/POGOProtos@b65d4b5
And is it possible to make it so you can set device/gps/sensor/activity info for each request. as currently it sets the signature without any of those fields.
Not sure if I am getting this.
I do something like:
require 'poke-api'
require 'awesome_print'
# Instantiate our client
client = Poke::API::Client.new
# Both PTC/Google available as authentication provider
client.store_location('New York')
client.store_lat_lng(40.712906, -74.007333) # Some random coordinates from NY (pulled from Google Maps)
client.login('some_username', 'password_here', 'ptc')
cell_ids = Poke::API::Helpers.get_cells(client.lat, client.lng)
# Construct map objects call
client.get_map_objects(
latitude: client.lat,
longitude: client.lng,
since_timestamp_ms: [0] * cell_ids.length,
cell_id: cell_ids
)
resp = client.call
puts resp.response
All I get are responses with no results:
[ 0] {
:s2_cell_id => some_cell_id_here,
:current_timestamp_ms => 1470811515476,
:forts => [],
:spawn_points => [],
:wild_pokemons => [],
:deleted_objects => [],
:is_truncated_list => false,
:fort_summaries => [],
:decimated_spawn_points => [],
:catchable_pokemons => [],
:nearby_pokemons => []
},
As in wild_pokemons
, catchable_pokemons
and nearby_pokemons
always returns with an empty array []
. Is there something I am missing?
I am creating an instance of Poke::API::Client and logging in, if it fails, and I try to re-log in, it fails continuously unless I create a new instance, I would try to help further but I had no luck getting it to fail when I turn logs to debug (tried for like 15 mins)
(main)> require 'poke-api'
=> true
(main)> lat = -23.59260639636282
=> -23.59260639636282
(main)> lng = -46.680191904206524
=> -46.680191904206524
(main)> Poke::API::Helpers.get_cells(lat, lng)
=> [
[ 0] 10722603741376151552,
[ 1] 10722603743523635200,
[ 2] 10722603745671118848,
[ 3] 10722603747818602496,
[ 4] 10722603749966086144,
[ 5] 10722603752113569792,
[ 6] 10722603754261053440,
[ 7] 10722603756408537088,
[ 8] 10722603758556020736,
[ 9] 10722603760703504384,
[10] 10722603762850988032,
[11] 10722603764998471680,
[12] 10722603767145955328,
[13] 10722603769293438976,
[14] 10722603771440922624,
[15] 10722603773588406272,
[16] 10722603775735889920,
[17] 10722603777883373568,
[18] 10722603780030857216,
[19] 10722603782178340864,
[20] 10722603784325824512
]
which does not contain the S2 Cell ID 10722603763924729856, whose center is lat, lng
.
Contrast this with sidewalklabs/s2sphere: Python implementation of the S2 geometry library:
>>> import s2sphere
>>> lat = -23.59260639636282
>>> lng = -46.680191904206524
>>> cell = s2sphere.Cell.from_lat_lng(s2sphere.LatLng.from_degrees(lat, lng))
>>> cell.id().parent(12).id()
10722603763924729856
Logging in with the API locally on my computer yields no errors. But when I try to use it on Heroku's servers I get this error.
Loading production environment (Rails 5.0.0)
irb(main):001:0> client = Poke::API::Client.new
=> #<Poke::API::Client @auth= @reqs=[] @lat=0 @lng=0 @alt=0>
irb(main):002:0> client.login("xxx","xxx","ptc")
[2016-07-31T04:49:03+00:00]: INFO > Poke::API::Client --: [+] Logging in user: xxx
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::Client --: [+] Login with PTC Successful
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Adding 'GET_PLAYER' to RPC request
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Adding 'GET_HATCHED_EGGS' to RPC request
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Adding 'GET_INVENTORY' to RPC request
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Adding 'CHECK_AWARDED_BADGES' to RPC request
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Adding 'DOWNLOAD_SETTINGS' to RPC request with arguments
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::RequestBuilder --: [+] Executing RPC request
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::Response --: [+] Decoding Main RPC responses
[2016-07-31T04:49:04+00:00]: INFO > Poke::API::Client --: [+] Cleaning up RPC requests
Poke::API::Errors::UnknownProtoFault: An unknown proto fault has occured => [Error occurred during parsing: Unmatched ENDGROUP tag. @ /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/response.rb:14:in `decode']
from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:39:in `rescue in call'
from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:43:in `call'
from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:70:in `fetch_endpoint'
from /app/vendor/bundle/ruby/2.2.0/bundler/gems/poke-api-85ee2d01f869/lib/poke-api/client.rb:29:in `login'
from (irb):2
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/console.rb:65:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/console_helper.rb:9:in `start'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:78:in `console'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /app/vendor/bundle/ruby/2.2.0/gems/railties-5.0.0/lib/rails/commands.rb:18:in `<top (required)>'
from bin/rails:9:in `require'
from bin/rails:9:in `<main>'
irb(main):003:0>
To replicate this error you have to make a Rails project and client.login through Heroku console (accessed by "heroku run console"). I don't know if this is a problem with the API, my development environment, or with heroku itself. But I have tried to figure this out for a while and have gotten nowhere. If anyone has any insight to Rails deployment to Heroku and possible culprits that would be great.
I am using Ruby 2.2.4 and Rails 5.0 and have tried deploying with Ruby 2.2.4 to no avail.
Are you going to implement this?
Currently getting:
/Users/foo/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/poke-go-api-0.1.7/lib/poke-api/client.rb:44:in `rescue in call': An unknown proto fault has occured => [unknown type: size_t input_size @ /Users/foo/.rbenv/versions/2.2.5/lib/ruby/2.2.0/fiddle/cparser.rb:171:in `parse_ctype'] (Poke::API::Errors::UnknownProtoFault)
from /Users/foo/.rbenv/versions/2.2.5/lib/ruby/gems/2.2.0/gems/poke-go-api-0.1.7/lib/poke-api/client.rb:48:in `call'
This just suddenly appeared. Im guessing due to PoGo API update?
Hey
What is encryption file and how i can get it?
Poke::API::Errors::LoginFailure: Unable to login to PTC => [undefined method to_h' for [["error", "invalid_grant"]]:Array @ /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/auth/ptc.rb:65:in
fetch_access_token']
from /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/client.rb:27:in rescue in login' from /Users/user/.rbenv/versions/2.0.0-p645/lib/ruby/gems/2.0.0/bundler/gems/poke-api-fd27b2c9834f/lib/poke-api/client.rb:23:in
login'
Hi there!
first of all thanks for your work.
I just have a simple question, I am currently stuck at understanding where the stuff from the fetch_endpoint method comes from:
get_player
get_hatched_eggs
get_inventory
check_awarded_badges
download_settings(hash: '4a2e9bc330dae60e7b74fc85b98868ab4700802e')
Where does it come from, what is it calling?
Thanks for any answer!
Niklas
I'm trying to do an api call that drops items from the inventory, I've used get_inventory
and then filtered the items that I want to drop, then I created a call like this
client.recycle_inventory_item(201, 10)
client.call
but then I get this error
Poke::API::Errors::UnknownProtoFault: An unknown proto fault has occured => [uninitialized constant RpcSub::RecycleInventoryItemRequest @ /[gem_path]/gems/poke-api-0.0.2/lib/poke-api/request_builder.rb:87:in `fetch_proto_request_class']
Is this because the RpcSub needs to map all requests, or am I doing something wrong?
Hello again,
I have tried to integrate the "release_pokemon" RPC call. The output of inspect is the following:
#<Poke::API::Client @auth=#<Poke::API::Auth::GOOGLE:0x007fef17898088> @reqs=[{:RELEASE_POKEMON=>{:pokemon_id=>"1234567890"}}] @lat=0 @lng=0 @alt=0>
(I changed the pokemon_id)
The error is the following:
Poke::API::Errors::UnknownProtoFault (An unknown proto fault has occured => [Expected number type for integral field. @ /xxx/ruby-2.3.0/bundler/gems/poke-api-3223d8bf915b/lib/poke-api/request_builder.rb:90:in
initialize']): app/controllers/pokemon_controller.rb:18:in
transfer'
Line 18 is simply the call = client.call
call.
I am not sure if I used the correct pokemon id, I guessed that this is the id
I get from the regular get_inventory
call. Is this correct or where do I get the pokemon id from?
Thanks for any help!
lat = some_lat_here
lng = some_lng_here
client.store_lat_lng(lat, lng)
cell_ids = Poke::API::Helpers.get_cells(lat, lng)
client.get_map_objects(
latitude: client.lat,
longitude: client.lng,
since_timestamp_ms: [0] * cell_ids.length,
cell_id: cell_ids
)
resp = client.call
puts resp.response[:GET_MAP_OBJECTS][:map_cells]
The following puts
returns objects. In forts
, I do see some results. But I dont see any indication of any pokestops. Does get_map_objects
support this, at this time?
Hi! I have a problem running the program because of the syntax error in gpsoauth. I'm trying to log in with google account.
The error looks like below. Do you know how to fix this problem? Thanks in adv.
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:26: syntax error, unexpected ':', expecting => (SyntaxError)
'accountType': 'HOSTED_OR_GOOGLE',
^
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:26: syntax error, unexpected ',', expecting keyword_end
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:27: syntax error, unexpected ':', expecting keyword_end
'Email': email,
^
/Library/Ruby/Gems/2.0.0/gems/gpsoauth-rb-0.1.2/lib/gpsoauth.rb:28: syntax error, unexpected ':', expecting :: or '[' or '.'
'has_permission': 1,
^
Please consider creating a chat here: https://gitter.im
I keep getting this issue when logging in with google:
INFO > Poke::API::Client --: [+] Logging in user: [email protected]
Poke::API::Errors::LoginFailure: Unable to login to GOOGLE => [undefined methodsplit' for :"user-agent":Symbol @ /Users/xxx/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/net/http/header.rb:172:in
capitalize']
To recreate:
client = Poke::API::Client.new
client.login("[email protected]","password","google")
Sometimes when a status is unsuccessful, it will return a code of 53 and a new api url. Can you add a method that checks for this and updates @endpoint
accordingly. example response:
{:GET_PLAYER=>{:success=>false, :player_data=>nil}, :status_code=>53, :api_url=>"pgorelease.nianticlabs.com/plfe/327", :error=>""}
An unknown proto fault has occured => [Error occurred during parsing: Unmatched ENDGROUP tag. @ /home/deploy/.bundler/pokedex_development/ruby/2.2.0/bundler/gems/poke-api-5f1a75a6e4ed/lib/poke-api/response.rb:16:in `decode']
Since Niantic is now blocking calls from major cloud services through IP detection - is there anyway we would implement the use of a proxy for HTTPClient ?
It could work this way:
client.store_proxy(url, user, pass)
And
def initialize(auth, pos, endpoint, proxy=nil, proxy_user=nil, proxy_password=nil)
@access_token = auth.access_token
@provider = auth.provider
@endpoint = endpoint
@position = pos
@client = HTTPClient.new(proxy)
@client.set_proxy_auth(user, password)
@client.header["User-Agent"] = 'PokeAPI/0.0.1'
@start_time = (Time.now.to_f * 1000).to_i
end
https://github.com/nabeelamjad/poke-api/blob/master/lib/poke-api/request_builder.rb
Hello, can you say how did you generated cell_id in the exmaple.rb ? And what cell_id we need?
pgoapi
has a set_position()
method. Wondering if such exists here as well? At the moment, I am only seeing what is specified in the docs
i.e. store_location('New York')
Since the 0.43.x API was released not so long ago (https://github.com/pogodevorg/pgoapi), any chance of updating the ruby version? (necessary for PoGoBag :) )
I know that it's old as my grandma ass but that's my hosting platform and can't change it. Can we do something about it? Do I have to make a pull request in gpsoauth reverting compatibility? I don't want to use Google Login....
It's getting slightly out of hand, will need to (time permitting) use Github's wiki and provide a proper documentation on what can and can not be done in their own section without cluttering everything.
Whats the difference between wild and catchable pokemons?
Edit for Clarification:
is it possible to do authentication with Google rather than the API.
For example:
- Redirect a user to the google sign in page and retrieve an access token there
- Using that access token retrieve the endpoint for the API
- Continue to make requests as needed from there.
The purpose of this is to allow for a more secure login rather than inputting your username and password into the API.
Do you plan to push this to rubygems.org? You can't use a git source as a gem dependency
Cna you implement using the auth ticket instead of using the oauth token, Seems to get errors a lot using token. Also can you add new error/log messages for IP ban/ throttle.
As seen here: https://github.com/tejado/pgoapi/blob/master/pgoapi/rpc_api.py#L122
I have the error
Poke::API::Errors::UnknownProtoFault - An unknown proto fault has occured => [uninitialized constant RpcSub::EvolvePokemonRequest
I think you need to require all the Protos files.
It's impossible to retrieve the ID of a Pokemon for example (you get :RATTATA
, and the POGOProtos.Enums.PokemonId
is required to retrieve the pokedex index of the pokemon)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.