小编JRQ*_*JRQ的帖子

使用Ruby中的Google Apps API和服务帐户时出现问题

我在获取用于实例化Drive Service帐户的示例代码时遇到了一些麻烦.我已按照指示在API控制台中设置服务帐户,并包含" https://www.googleapis.com/auth/drive " 的范围,但运行此帐户会生成以下错误:"授权失败.服务器消息:(Signet :: AuthorizationError)".

奇怪的是,如果我省略user_email地址,它不会产生错误.

我的目标是能够对组织的驱动器上存储的所有文件进行审核,我的理解是使用服务帐户可以获得存储的所有文件的列表.

我是否错过了服务器端的一些特殊设置?

require 'google/api_client'

## Email of the Service Account #
SERVICE_ACCOUNT_EMAIL = '<service account email>@developer.gserviceaccount.com'

## Path to the Service Account's Private Key file #
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '<private key file>-privatekey.p12'

def build_client(user_email)
    key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'notasecret')
    asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, 'https://www.googleapis.com/auth/drive', key)
    client = Google::APIClient.new

    client.authorization = asserter.authorize(user_email)
    return client
end

client = build_client("<users email address>")
Run Code Online (Sandbox Code Playgroud)

ruby google-api google-drive-api google-api-ruby-client

3
推荐指数
1
解决办法
1942
查看次数

确定"discovered_api"的参数

这可能是一个非常愚蠢的问题,但是如何确定在客户端"discovered_api"调用中传递的参数?什么是执行的"api_method"

例如,我正在尝试调用"GET https://www.googleapis.com/admin/directory/v1/users " 的Admin SDK用户列表调用.

似乎没有一种明确的方法从API参考中提取这个,或者我只是在错误的地方寻找?

google-api-ruby-client

2
推荐指数
1
解决办法
1037
查看次数