Pregunta

I am trying to access Google api client (Ruby) without Oauth.. I have found this info:

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

But unfortunately, if I follow the instructions (Here 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

"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup"

What is wrong?

¿Fue útil?

Solución

In a nutshell, all of the discovery-based APIs require your calls to be identified. The error you're getting is what I usually see when a Google API can't identify your app. You can usually make a handful of unidentified calls, but you'll almost certainly run into the much-lower "unidentified" quota pretty quickly. You can either authenticate with OAuth (which identifies your app) or you can specify an API key (which identifies your app) or you can do both.

This is done by setting client.key = "<your api key>" or by passing it into the client constructor (as you've done). You should probably also set client.user_ip = request.remote_ip (or whatever gets the IP address of the client in your framework of choice), particularly if you're not authenticating with OAuth.

It looks like you're already setting the API key from your example, but it's possible you've got a typo or the key from the wrong API project or you're running into per-user limits, which setting the user_ip would resolve. Another thing it's important to understand is that quotas may be specified in terms of queries per day, but then enforced per minute or per hour or over some other time period. So you might have a 10k QPD quota, but that's only 415 QPH or 7 QPM. I don't know how the YouTube quotas are enforced, but it's something to keep in mind.

One thing you shouldn't need to do is set the :key in the :parameters argument to your API call. If you want to set it on a per-request basis, that's just passed in directly as another optional parameter to execute. That should be handled automatically by the client in your case. Probably best to drop that from your code since you've already set it in the constructor.

Final 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"
  }
)

Otros consejos

In the API Console is a Quotas Pane that will tell you your daily limit for that praticular API key. Are you reusing someone else's key? The limit could also be low if you haven't provided billing information (or it could be a resource that only works over oAuth)

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top