How to access google api client without Oauth (API key only)

I am trying to access Google Api (Ruby) client without Oauth .. I found this information:

http://thecodeabode.blogspot.com.au/2012/07/google-api-ruby-client-authorizing-with.html

But unfortunately if I follow the instructions (this is what I do):

 require 'google/api_client'
 client = Google::APIClient.new(:key => "MYKEY",:authorization => nil)    
 yt = client.discovered_api("youtube", "v3")
 result = client.execute(
   :api_method => yt.search.list,
   :parameters => {
     :key => "MYKEY",
     :q => "dogs",
     :part => "topicDetails"
   }
 )

      

I get

"The daily limit for unreliable use has been exceeded. Continued use requires registration."

What's wrong?

+1


source to share


2 answers


In short, all discovery-based APIs require your calls to be identified. The error you are getting is what I usually see when the Google API is unable to detect your application. You can usually make several unidentified calls, but you will almost certainly run into a much lower "unrecognized" quota pretty quickly. You can either authenticate with OAuth (which identifies your app), or you can provide an API key (which identifies your app), or you can do both.

This is done by setting client.key = "<your api key>"

or passing it to the client's constructor (as you did). You should probably also install client.user_ip = request.remote_ip

(or whatever gets the client IP in your fetch), especially if you are not OAuth authenticated.

It looks like you are already setting the API key from your example, but perhaps you have a typo or key from the wrong API project, or you are working with per-user constraints that set the value user_ip

. Another important thing to understand is that quotas can be quoted in terms of requests per day, but then enforced per minute or hour, or some other period of time. So you might have a 10k QPD quota, but that's only 415 QPH or 7 QPM. I don't know how YouTube quotas are applied, but this must be borne in mind.



One thing you don't need to do is set :key

in the argument :parameters

for the API call. If you want to set it for every request, that is just passed directly as another optional parameter to execute

. This should be automatically handled by the client in your case. It is probably best to discard this code as you have already set it in the constructor.

The end result should be:

require 'google/api_client'
client = Google::APIClient.new(:key => "MYKEY", :authorization => nil)    
yt = client.discovered_api("youtube", "v3")
result = client.execute(
  :api_method => yt.search.list,
  :authenticated => false,
  :user_ip => request.remote_ip,
  :parameters => {
    :q => "dogs",
    :part => "topicDetails"
  }
)

      

+1


source


There is a Quotas panel in the API console that will tell you your daily limit for this praticular API key. Are you reusing a different key? The limit can also be low if you haven't provided billing information (or it might be a resource that only works with oAuth).



0


source







All Articles