Ruby on rails: Google API dailyLimitExceededUnreg - google-api

Hey guys I have an error when getting some tokens from google. Do you have any ideas about this error? And let me know how I can solve this error.
[{"domain"=>"usageLimits", "reason"=>"dailyLimitExceededUnreg", "message"=>"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.", "extendedHelp"=>"https://code.google.com/apis/console"}], "code"=>403, "message"=>"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."}}
My fetching code:
def self.request_tokens(code)
Request.post('https://www.googleapis.com/oauth2/v4/token', {
client_id: 'XXXXXXXXXXXXXX',
client_secret: 'XXXXXXXXXXXXXX',
redirect_uri: 'http://localhost:8080',
grant_type: 'authorization_code',
code: code,
})
end
def self.request_profile(access_token)
Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}")[:body]
end
Add:
I have already added API key like this.
def self.request_profile(access_token)
  # Add api key but failed
Request.get("https://www.googleapis.com/plus/v1/people/me?access_token=#{access_token}?key=XXXXXXXXXXXXX")[:body]
  # try like this but failed
plus = Google::Apis::PlusV1::PlusService.new
plus.key = 'XXXXXXXXXXXXX'
plus.authorization = access_token
end

It means exactly what it says. You're overusing Google's API, so they're not letting you use it for the rest of the day unless you sign up for an API key. https://code.google.com/apis/console, the link in your error, will let you do that.

"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
Means that you are trying to access a Google api without being authenticated or using an api key (using a valid client). In order to access all google apis you must have created a project on Google developer console. If you are accessing public data you can use an api key if you are accessing private user data you will need to use Oauth2.
You appear to have tried to set the client id in your code. The issue is that its not being applied properly to your request. I am not a ruby dev so can not assist you in debugging your code how ever google has a number of ruby tutorials OAuth 2.0
as well as use api key
require 'google/apis/plus_v1'
plus = Google::Apis::PlusV1::PlusService.new
plus.key = 'api_key'

Related

Expected top level property 'installed' or 'web' to be present. google-apis-ruby quickstart

I have been attempting to get device information using the google/apis/admin_directory_v1 api.
I found a ruby quickstart that happens to use this exact api in the example. However when I follow the instructions and try to run the script that is listed in the link I get the error ...
"Expected top level property 'installed' or 'web' to be present."
A link to the quickstart is below.
EDITED SORRY I WAS OVER TIRED LOL
https://developers.google.com/admin-sdk/directory/v1/quickstart/ruby
I have been trying to return results from the API all day and it has pushed me to write this post. Please don't attack me I am merely trying to help someone else in the future with this because the documentation is very cavernous for something as simple as api requests?
Anyway I have no idea what the error means or how to proceed. I have fixed enough errors with this situation for one night and now I am just hoping to meet someone else who has traveled this road.
Edited: Sorry to post the wrong link I was too tired. I was never using anything related to the sheets link I must have had the tab open for researched and just pasted the wrong link.
Edited Again: I have gotten a bit further but still no success... Well actually I take that back I am geting a confirmed bearer token back I am just unsure how to use it properly with this api client... The test I am currently working with is below...
require "google/apis/admin_directory_v1"
require "googleauth"
require "googleauth/stores/file_token_store"
require "fileutils"
APPLICATION_NAME = "Directory API Ruby Quickstart".freeze
CREDENTIALS_PATH = "credentials.json".freeze
CUSTOMER_ID = "xxxxxxx".freeze
SCOPE = Google::Apis::AdminDirectoryV1::AUTH_ADMIN_DIRECTORY_USER_READONLY
def authorize
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('credentials.json'),
scope: SCOPE)
authorizer.fetch_access_token!
end
# puts authorize
# Initialize the API
service = Google::Apis::AdminDirectoryV1::DirectoryService.new
service.client_options.application_name = APPLICATION_NAME
service.authorization = Google::Auth.get_application_default(SCOPE)
response = service.list_mobile_devices(customer_id: CUSTOMER_ID)
puts response.to_json
This is returning the error below
/var/lib/gems/2.7.0/gems/google-apis-core-0.4.2/lib/google/apis/core/http_command.rb:229:in `check_status': PERMISSION_DENIED: Request had insufficient authentication scopes. (Google::Apis::ClientError)
I would assume that this should be possible with a service account and that I am still making a simple mistake....
The issue you are having is that the Ruby quickstart for Google sheets was designed for use with an installed application.
You are directed to create installed credentials. Here is a video as well How to create Google Oauth2 installed application credentials.json.
Authorization credentials for a desktop application. To learn how to create credentials for a desktop application, refer to Create credentials.
This error message is telling you that you did not create that type of credentials. Did you try to create service account credentials maybe? That wont work with this code.

GET /admin/webhooks.json returns an empty array

When doing GET /admin/webhooks.json it simply returns:
{"webhooks"=>[]}
I've created 8 webhooks using the admin panel but I can't seem to access them using the API. If I enter https://SHOP_NAME.myshopify.com/admin/webhooks.json directly into the browser it does return all the webhooks.
Here's the call I'm making using the credentials from a private app:
require 'httparty'
data = HTTParty.get("https://<API_KEY>:<PASSWORD>#<SHOP_NAME>.myshopify.com/admin/webhooks.json", :headers => {'Content-Type' => 'application/json'})
Any idea what I'm doing wrong?
Scanning through the Shopify API authentication docs doesn't give any indication that HTTP basic authentication of the form https://<API_KEY>:<PASSWORD>#... is supported.
This may be the reason why you can't query the hooks. In you browser you may use a web session. You can verify by removing the basic auth from the url and open again in you browser
https://<SHOP_NAME>.myshopify.com/admin/webhooks.json
The /admin/webhooks.json endpoint only returns the webhooks that you have registered with that API key. That's why I'm seeing an empty array.

OAuth token parameter missing when using request_youtube API

I try to using youtube API in code ingniter and using librari from https://github.com/jimdoescode/CodeIgniter-YouTube-API-Library when i call request_youtube()from direct link the https://accounts.google.com/o/oauth1/auth sent massage like this :
400. That’s an error.
OAuth token parameter missing.
That’s all we know.
This the code of request_youtube() :
public function request_youtube()
{
$params['key'] = xxxxxxxxxxxx.apps.googleusercontent.com';
$params['secret'] = 'xxxxxxxxxxxx';
$params['algorithm'] = 'HMAC-SHA1';
$this->load->library('google_oauth', $params);
$data = $this->google_oauth->get_request_token(base_url().'index.php/example/access_youtube');
$this->session->set_userdata('token_secret', $data['token_secret']);
redirect($data['redirect']);
}
what wrong with my code...or any step i miss???
The library that you are using is deprecated probably because of which it is unable to make calls to the Google Servers and is returning 404 errors. You can still follow the original way of authentication using OAuth where you validate your app with the client id client secret and get the Auth code. With the Auth code making a POST request and getting a access token and a refresh token in exchange. For details please refer to this official Google Youtube Documentation on OAuth.

Spring Social .NET OAuth confusion

I had originally posted a question about what API to use in regards to making a SharePoint 2010 timer job able to access the twitter API and chose the Spring Social .NET api and have run into another roadblock.
I cannot get the OAuth handshake or 'dance' to work.
I have the consumer key and secret linked to my account, as well as an access token and secret, but any time I try to initialize a TwitterServiceProvider object, any time I attempt to query I get a 401 error.
The console/mvc and wp7.1 examples provided dont give much insight how I can get this code (which should run with no human involvement) to work.
Does anyone have any good resources regarding this?
Thanks in advance
If you already have access token value and secret, you can do something like that:
ITwitter twitter = new TwitterTemplate("consumerKey", "consumerSecret", "accessTokenValue", "accessTokenSecret");
// twitterApi.UserOperations.GetUserProfile();
that is equivalent to :
TwitterServiceProvider serviceProvider = new TwitterServiceProvider("consumerKey", "consumerSecret");
ITwitter twitterApi = serviceProvider.GetApi("accessTokenValue", "accessTokenSecret");
// twitterApi.UserOperations.GetUserProfile();
How do you get the access token secret and value?

how to authorizate use google-api-ruby-client

i am using google api for ruby, but not know how to start, just give me an ABC example someone, thanks very much?
If you are creating a Service Account application to access Google Analytics.
Register it with Google through https://code.google.com/apis/console.
On API Access tab, click Create client ID, choose Service Account. Store the key file Google will generate, and remember the password for that key.
Here is some code to get you started
require 'rubygems'
require 'google/api_client'
api_client = Google::APIClient.new
path_to_key_file ="/path/to/key/file-privatekey.p12"
passphrase = "google_generated_password"
key = Google::APIClient::PKCS12.load_key(path_to_key_file, passphrase)
Once a key is available, initialize the asserter with your client ID (email in APIs console)
and authorization scopes.
asserter = Google::APIClient::JWTAsserter.new(
'super_long_client_id_from_api_console#developer.gserviceaccount.com',
'https://www.googleapis.com/auth/analytics.readonly',
key)
# To request an access token, call authorize:
api_client.authorization = asserter.authorize()
puts api_client.authorization.access_token
http://code.google.com/p/google-api-ruby-client/wiki/ServiceAccounts
I've answered something similar in a couple of other posts I found that were like this one... so incase its relevant, for ruby, using the google-api-client (for any of the google apis), there's a few ins and outs with authentication when using an api key as opposed to OAuth...
I've outlined this process (using an api key server side) at the code abode.
You have to explicitly set the authorzation param to nil when constructing the client, otherwise the gem tries to use OAuth to authenticate, so if calling from a server using an api key only, you will always get a 401 Unauthorized.
the code abode - google-api-client for ruby

Resources