Souman Mandal
Souman Mandal

Reputation: 115

Google-api-client asking for access token

My requirement is to get top 20 links for a search query in google.com. I am using the Google-api-client! for ruby.

Here goes the code I am using,

require 'google/api_client'
client = Google::APIClient.new
response = client.execute(
    search.cse.list, 'key' => '<My Key>', 'cx' => '013036536707430787589%3A_pqjad5hr1a', 'alt' => 'json', 'q' => 'hello world'
)

Now I am facing three problems,

  1. I want to use default Google search, so what should be the 'cx' value? One which I used, is from https://developers.google.com/custom-search/v1/using_rest#cx
  2. I am getting no results, instead getting the following warning "ArgumentError: Missing access token." I solved this issue using a dummy token, by defining "client.authorization.access_token = '123'" . But I am not sure, if it is a correct solution or not.
  3. After I define the access_token, still I am getting no result. Instead getting the warning "Invalid Credentials". But if I use the same URL(generated by the api), in the browser I am getting results.

Upvotes: 1

Views: 2287

Answers (1)

Steve Bazyl
Steve Bazyl

Reputation: 11662

Instead of setting a dummy access token, just set the authorization mechanism to nil:

client.authorization = nil

This way it won't send an authorization header and will just rely on the API key for identifying your app.

Upvotes: 9

Related Questions