node-google-play icon indicating copy to clipboard operation
node-google-play copied to clipboard

Search offset doesn't work

Open jmike opened this issue 10 years ago • 6 comments

Seems that "offset" param in the search() method doesn't do anything.

The code below produces the following results:

client.search('facebook', 5, 0)
  .then((results) => {
    console.log(results[0].child.map((e) => e.details.appDetails.packageName));
  })
[ 'com.facebook.katana',
  'com.facebook.lite',
  'com.facebook.orca',
  'com.facebook.work',
  'com.facebook.stickered' ]

But when I change the offset from 0 to 5 I still get the same results.

client.search('facebook', 5, 5)
  .then((results) => {
    console.log(results[0].child.map((e) => e.details.appDetails.packageName));
  })
[ 'com.facebook.katana',
  'com.facebook.lite',
  'com.facebook.orca',
  'com.facebook.work',
  'com.facebook.stickered' ]

Do you know if Google have changed their API? I am pretty sure this was working fine a few months ago.

jmike avatar Aug 18 '15 06:08 jmike

I confirmed locally that the offset parameter isn't working currently. I'm investigating whether the parameter has changed and will get back to you.

dweinstein avatar Aug 18 '15 22:08 dweinstein

yeah it looks like they got rid of the offset (o) parameter. max size of 100 seems to be all we're able to do now. I'll update the code to reflect that and maybe warn with some kind of deprecation warning on requests with an offset being set.

dweinstein avatar Aug 18 '15 22:08 dweinstein

FYI search response contains a nextPageUrl property, specifically response.payload.searchResponse.doc[0].containerMetadata.nextPageUrl.

Using that URL one can iterate over the result pages.

jmike avatar Aug 19 '15 06:08 jmike

nice. yeah the containerMetadata field is described here https://github.com/dweinstein/google-play-proto/blob/master/googleplay.proto#L546-L554 -- I suppose I could return an iterator that would allow requests to walk the nextPages, but that would probably have to be exposed as a different method name on the API object.

Thoughts on this?

dweinstein avatar Aug 19 '15 14:08 dweinstein

Iterator is an excellent idea! As for exposing new search functionality under a different method name, I believe this is a matter of preference. The way things are going with Google Play the search method will be useless unless people are only looking to get the 1st page of the results. So why not change it completely and bump the major version of the project? Again, this is a matter of preference.

The only alternative I can think of is iterating the pages internally and collecting the results in a single array to return.

jmike avatar Aug 20 '15 06:08 jmike

How do you go about using the nextPageUrl to navigate to the next page? I'm new to node.

Right now I am just using the search function example with the command running node search.js etc etc etc

function search (term, n, offset) { return api.search(term, n, offset).then(function (res) { console.log('%j', res); }); }

How can I retrieve the nextPageUrl and navigate to it?

jberlynn avatar Aug 03 '17 18:08 jberlynn