When attempting to retrieve Google Contacts via PeopleV1 API in Ruby Rails, why do I get "ArgumentError: unknown keyword: person_fields"?
When attempting to retrieve Google Contacts via PeopleV1 API in Ruby Rails, why do I get "ArgumentError: unknown keyword: person_fields"?
我在 Rails 5(版本 5.1.5)应用程序上很难将 Google 联系人集成到我的 Ruby(版本 2.2.10)中。
当我执行以下代码块时,我收到 "ArgumentError: unknown keyword: person_fields"。
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10,
person_fields: 'names,emailAddresses')
为了纠正这个问题,我尝试使用以下 gem 版本:
gem 'google-api-client', '~> 0.11'
gem 'google-api-client', '~> 0.8'
gem 'google-api-client'
无论我使用哪个版本的gem,我仍然会收到错误消息。
完整代码如下:
require 'google/apis/people_v1'
require 'google/api_client/client_secrets'
client_secrets = Google::APIClient::ClientSecrets.load 'client_secret_1088824912015-f8asojku302s0mvcijgj7takse8pg8rg.apps.googleusercontent.com.json'
auth_client = client_secrets.to_authorization
auth_client.update!( :scope => 'https://www.googleapis.com/auth/contacts.readonly', :redirect_uri => 'http://localhost:3000/oauth2callback', :additional_parameters => { "access_type" => "offline", "include_granted_scopes" => "true" } )
auth_uri = auth_client.authorization_uri.to_s
# To exchange an authorization code for an access token, use the fetch_access_token! method:
auth_client.code = #auth_code#
auth_client.fetch_access_token!
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10, person_fields: 'names,emailAddresses')
如有任何帮助,我们将不胜感激。
正确的属性是 fields
而不是 person_fields
。请参阅文档 here.
只是为了向任何未来的读者澄清,Ray Baxte 链接到与 google-api-client
gem 的 0.9.19
版本相对应的文档 - 当前版本是 0.27.1
我正在使用 0.26.0
并且正确的参数是 person_fields
- 这显然在 0.9.19
和 0.26.0
之间的某处发生了变化
我遵循生成的 API 方法定义中的文档:
https://github.com/googleapis/google-api-ruby-client/blob/0.27.1/generated/google/apis/people_v1/service.rb#L591
我在 Rails 5(版本 5.1.5)应用程序上很难将 Google 联系人集成到我的 Ruby(版本 2.2.10)中。
当我执行以下代码块时,我收到 "ArgumentError: unknown keyword: person_fields"。
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10,
person_fields: 'names,emailAddresses')
为了纠正这个问题,我尝试使用以下 gem 版本:
gem 'google-api-client', '~> 0.11'
gem 'google-api-client', '~> 0.8'
gem 'google-api-client'
无论我使用哪个版本的gem,我仍然会收到错误消息。
完整代码如下:
require 'google/apis/people_v1'
require 'google/api_client/client_secrets'
client_secrets = Google::APIClient::ClientSecrets.load 'client_secret_1088824912015-f8asojku302s0mvcijgj7takse8pg8rg.apps.googleusercontent.com.json'
auth_client = client_secrets.to_authorization
auth_client.update!( :scope => 'https://www.googleapis.com/auth/contacts.readonly', :redirect_uri => 'http://localhost:3000/oauth2callback', :additional_parameters => { "access_type" => "offline", "include_granted_scopes" => "true" } )
auth_uri = auth_client.authorization_uri.to_s
# To exchange an authorization code for an access token, use the fetch_access_token! method:
auth_client.code = #auth_code#
auth_client.fetch_access_token!
people = Google::Apis::PeopleV1::PeopleService.new
people.authorization = auth_client
response = people.list_person_connections('people/me', page_size: 10, person_fields: 'names,emailAddresses')
如有任何帮助,我们将不胜感激。
正确的属性是 fields
而不是 person_fields
。请参阅文档 here.
只是为了向任何未来的读者澄清,Ray Baxte 链接到与 google-api-client
gem 的 0.9.19
版本相对应的文档 - 当前版本是 0.27.1
我正在使用 0.26.0
并且正确的参数是 person_fields
- 这显然在 0.9.19
和 0.26.0
我遵循生成的 API 方法定义中的文档: https://github.com/googleapis/google-api-ruby-client/blob/0.27.1/generated/google/apis/people_v1/service.rb#L591