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

462 Views Asked by At

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

Error when running the example script

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....

1

There are 1 best solutions below

2
Linda Lawton - DaImTo On

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.