serpapi / google-search-results-ruby

Google Search Results via SERP API Ruby Gem
https://serpapi.com
MIT License
59 stars 9 forks source link

Gem forces the use of `q` parameter for engines that is not used #10

Open hartator opened 2 years ago

hartator commented 2 years ago

We have several engines that work without a q parameter.

For example, Yande uses text:

image

And you can't submit your search to the API.

Hash with all engines that don't use q parameter:

{
  ebay: '_nkw',
  google_maps_reviews: 'data_id',
  google_product: 'product_id',
  google_scholar_author: 'author_id',
  google_scholar_profiles: 'mauthors',
  home_depot_product: 'product_id',
  walmart: 'query',
  walmart_product: 'product_id',
  yahoo: 'p',
  yandex: 'text',
  youtube: 'search_query',
  naver: 'query',
  apple_app_store: 'term',
  apple_reviews: 'product_id',
  yahoo_shopping: 'p',
  google_play_product: 'product_id',
}

We can explicitly check on this but I think it will easier to just drop the requirement of a q parameter for all engines.

DEADF00D commented 2 years ago

Happened again

Request: {
  :engine=>"yahoo", 
  :p=>"serpapi", 
  :api_key=>"<censored>"
}

/home/<censored>/.gem/ruby/3.0.0/gems/google_search_results-2.2.0/lib/search/serp_api_search.rb:178:in `check_params': missing required keys in params:  (SerpApiException)
 - q
        from /home/<censored>/.gem/ruby/3.0.0/gems/google_search_results-2.2.0/lib/search/google_search.rb:36:in `initialize'
        from se_everywhere.rb:41:in `new'
        from se_everywhere.rb:41:in `block in <main>'
        from se_everywhere.rb:32:in `each'
        from se_everywhere.rb:32:in `<main>'
DEADF00D commented 2 years ago

Actually, The library the right, and playground is false. Yahoo requirements are already defined under the YahooSearch class:

class YahooSearch < SerpApiSearch
  def initialize(params = {})
    super(params, YAHOO_ENGINE)
    check_params([:p, :engine])
  end
  ...
end

By replacing the GoogleSearch class by YahooSearch. It's now working.

We should fix code generation from API Playground to change class depending of the engine used.

paigebutler commented 1 year ago

I'm still facing the same issue with yahoo

Screen Shot 2023-03-01 at 2 46 14 PM
jvmvik commented 1 year ago

This is resolved by https://github.com/serpapi/serpapi-ruby The gem should be published soon.

sonika-serpapi commented 4 months ago

+1 Seeing this issue when using the google_search_results ruby gem. Is there a pending fix for this? Also, I noticed the gem for the https://github.com/serpapi/serpapi-ruby library doesn't exist and that the library is in draft stage at the moment. I want to suggest adding a note about it in the github documentation (readme, etc) can be helpful.