预期的顶级属性已安装'或Web'在场。 Google-apis-Ruby Quickstart

发布于 2025-01-27 10:22:12 字数 2023 浏览 3 评论 0原文

我一直在尝试使用Google/apis/admin_directory_v1 API获取设备信息。

我发现了一个Ruby Quickstart,恰好在示例中使用了此精确的API。但是,当我遵循说明并尝试运行链接中列出的脚本时,我会收到错误...

"Expected top level property 'installed' or 'web' to be present."

下面是QuickStart的链接。 编辑对不起,我累了大声笑 https://developers.google.com/admin-sdk/directory/ v1/quickstart/ruby

“运行示例脚本时的错误”

我一直在尝试从API返回API的结果。一天,这促使我写这篇文章。请不要攻击我,我只是在将来尝试帮助别人,因为文档对像API请求一样简单的东西非常壮观?

无论如何,我不知道错误的含义或如何进行。我已经在这种情况下解决了足够的错误,现在我只是希望见到旅行这条路的其他人。

编辑:很抱歉发布错误的链接我太累了。我从来没有使用过与纸链接有关的任何东西,我必须打开标签以进行研究并粘贴错误的链接。

再次编辑:我已经进一步了,但仍然没有成功...好吧,实际上我会收回确认的携带者令牌,我只是不确定如何与此API客户端正确使用它...我是测试我是目前与IS一起工作...

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

这是在下面返回错误,

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南巷近海 2025-02-03 10:22:12

您遇到的问题是用于Google Sheets的Ruby QuickStart 与已安装的应用程序一起使用。

您被指示创建已安装的凭据。这是一个视频,也是如何创建Google oauth2安装的应用程序凭证。

桌面应用程序的授权凭证。要了解如何为桌面应用程序创建凭据,请参阅创建凭据。

此错误消息告诉您您没有创建这种类型的凭据。您是否尝试创建服务帐户凭据?该代码无法使用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文