Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby google admin directory v1 api组。列表权限不足错误_Ruby_Google Api_Google Admin Sdk_Google Groups Api_Google Api Ruby Client - Fatal编程技术网

Ruby google admin directory v1 api组。列表权限不足错误

Ruby google admin directory v1 api组。列表权限不足错误,ruby,google-api,google-admin-sdk,google-groups-api,google-api-ruby-client,Ruby,Google Api,Google Admin Sdk,Google Groups Api,Google Api Ruby Client,我正试图授权谷歌管理api和列表邮件列表用户。我从api控制台下载了一个密钥,并执行了以下操作: require 'google/api_client' client= Google::APIClient.new(application_name: "myapp", application_version: "0.1") groups= client.discovered_api('admin', 'directory_v1') key = Google::APIClient::PKCS12.l

我正试图授权谷歌管理api和列表邮件列表用户。我从api控制台下载了一个密钥,并执行了以下操作:

require 'google/api_client'
client= Google::APIClient.new(application_name: "myapp", application_version: "0.1")
groups= client.discovered_api('admin', 'directory_v1')
key = Google::APIClient::PKCS12.load_key(Dir['*.p12'].first, 'notasecret')

client.authorization = Signet::OAuth2::Client.new(
  token_credential_uri: 'https://accounts.google.com/o/oauth2/token',
  audience: 'https://accounts.google.com/o/oauth2/token',
  scope: 'https://www.googleapis.com/auth/admin.directory.group.readonly',
  issuer: '123asdf@developer.gserviceaccount.com',
  signing_key: key)
client.authorization.fetch_access_token!

puts client.execute(api_method: groups.users.list, parameters: {}).body
我尝试添加groupKey:“mygroup@googlegroups.com" 我试着设置域名:“mysite.com” 它总是导致“权限不足”

要在组中列出用户,我还需要做什么呢?

尝试以下方法:

require 'google/api_client'

## Email of the Service Account #
SERVICE_ACCOUNT_EMAIL = '<some-id>@developer.gserviceaccount.com'

## Email account of the Admin User ##
ADMIN_EMAIL = 'your-google-admin@yourdomain.com'

## Path to the Service Account's Private Key file #
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/path/to/<public_key_fingerprint>-privatekey.p12'

##
# Build an Admin SDK client instance authorized with the service account
# that acts on behalf of the given user.
#
# @param [String] user_email
#   The email of the user.
# @return [Google::APIClient]
#   Client instance
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/admin.directory.group.readonly', key)
    client = Google::APIClient.new
    client.authorization = asserter.authorize(ADMIN_EMAIL)
    client
end
需要“google/api\u客户端”
##服务帐户的电子邮件地址#
服务\帐户\电子邮件='@developer.gserviceaccount.com'
##管理员用户的电子邮件帐户##
ADMIN_EMAIL='你的谷歌-admin@yourdomain.com'
##服务帐户的私钥文件的路径#
服务\帐户\ PKCS12\文件\路径='/PATH/to/-privatekey.p12'
##
#构建使用服务帐户授权的Admin SDK客户端实例
#代表给定用户的。
#
#@param[String]用户\电子邮件
#用户的电子邮件。
#@return[Google::APIClient]
#客户端实例
def构建客户端(用户电子邮件)
key=Google::APIClient::PKCS12.load\密钥(服务\帐户\ PKCS12\文件\路径,'notasecret')
asserter=Google::APIClient::JWTAsserter.new(服务\帐户\电子邮件、,
'https://www.googleapis.com/auth/admin.directory.group.readonly",键)
client=Google::APIClient.new
client.authorization=asserter.authorization(管理员电子邮件)
客户
结束
这大致是根据文件改编的。将服务帐户与管理员SDK目录API一起使用时,您仍然需要模拟管理员用户。

请尝试以下操作:

require 'google/api_client'

## Email of the Service Account #
SERVICE_ACCOUNT_EMAIL = '<some-id>@developer.gserviceaccount.com'

## Email account of the Admin User ##
ADMIN_EMAIL = 'your-google-admin@yourdomain.com'

## Path to the Service Account's Private Key file #
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/path/to/<public_key_fingerprint>-privatekey.p12'

##
# Build an Admin SDK client instance authorized with the service account
# that acts on behalf of the given user.
#
# @param [String] user_email
#   The email of the user.
# @return [Google::APIClient]
#   Client instance
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/admin.directory.group.readonly', key)
    client = Google::APIClient.new
    client.authorization = asserter.authorize(ADMIN_EMAIL)
    client
end
需要“google/api\u客户端”
##服务帐户的电子邮件地址#
服务\帐户\电子邮件='@developer.gserviceaccount.com'
##管理员用户的电子邮件帐户##
ADMIN_EMAIL='你的谷歌-admin@yourdomain.com'
##服务帐户的私钥文件的路径#
服务\帐户\ PKCS12\文件\路径='/PATH/to/-privatekey.p12'
##
#构建使用服务帐户授权的Admin SDK客户端实例
#代表给定用户的。
#
#@param[String]用户\电子邮件
#用户的电子邮件。
#@return[Google::APIClient]
#客户端实例
def构建客户端(用户电子邮件)
key=Google::APIClient::PKCS12.load\密钥(服务\帐户\ PKCS12\文件\路径,'notasecret')
asserter=Google::APIClient::JWTAsserter.new(服务\帐户\电子邮件、,
'https://www.googleapis.com/auth/admin.directory.group.readonly",键)
client=Google::APIClient.new
client.authorization=asserter.authorization(管理员电子邮件)
客户
结束

这大致是根据文件改编的。在将服务帐户与Admin SDK目录API一起使用时,您仍然需要模拟Admin用户。

我也遇到过同样的问题。我写了一个示例要点,解释了如何设置它:

步骤如下:

  • 转到Google云控制台()
  • 使用P12文件创建服务帐户
  • 在API中启用管理SDK
  • 创建项目
  • 在此项目中创建已注册的应用程序
  • 转到“证书”部分并生成密钥
  • 下载JSON文件
  • 转到应用程序控制台>安全>扩展>第三方OAuth ()
  • 添加一个API客户端。Client name是JSON中Client_id的值 文件,API作用域为

  • 我也有同样的问题。我写了一个示例要点,解释了如何设置它:

    步骤如下:

  • 转到Google云控制台()
  • 使用P12文件创建服务帐户
  • 在API中启用管理SDK
  • 创建项目
  • 在此项目中创建已注册的应用程序
  • 转到“证书”部分并生成密钥
  • 下载JSON文件
  • 转到应用程序控制台>安全>扩展>第三方OAuth ()
  • 添加一个API客户端。Client name是JSON中Client_id的值 文件,API作用域为

  • 我将ADMIN_EMAIL设置为用于控制api控制台的电子邮件。结果是:`fetch\u access\u token':授权失败。服务器消息:(Signet::AuthorizationError){“error”:“invalid_grant”}`我只启用了管理SDK和组设置。(这是免费层)这可能不适用于Google Apps标准/免费帐户。我将ADMIN_电子邮件设置为用于控制api控制台的电子邮件。结果是:`fetch\u access\u token':授权失败。服务器消息:(Signet::AuthorizationError){“error”:“invalid_grant”}`我只启用了管理SDK和组设置。(这是免费层)这可能不适用于谷歌应用程序标准/免费帐户。