Google-api-client asking for access token

别来无恙 提交于 2020-01-15 09:45:11

问题


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.

回答1:


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.



来源:https://stackoverflow.com/questions/10811804/google-api-client-asking-for-access-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!