- You need
Google Workplace Account
- Create/add contacts to the account
- Create Service Account from the google workplace account cloud console.
- Enable the
People API
- Add the service account to the google workplace
Domain Wide Delegation
- Update the code to your settings.
- Run the code
Last active
June 27, 2023 02:46
-
-
Save syafiqfaiz/d102f56bc2a4ee7a7ef02eaa48743bd5 to your computer and use it in GitHub Desktop.
How to use Google People V1 API using service acccount in Ruby.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'google/apis/people_v1' | |
require 'googleauth' | |
# Set up authorization | |
scopes = ['https://www.googleapis.com/auth/contacts'] | |
credentials = Google::Auth::ServiceAccountCredentials.make_creds( | |
json_key_io: File.open('g_suite_service_account.json'), | |
scope: scopes, | |
) | |
credentials.sub = 'the_account_you_want_to_use@email.com' | |
# Authorize the client | |
client = Google::Apis::PeopleV1::PeopleServiceService.new | |
client.authorization = credentials | |
response = client.list_person_connections( | |
'people/me', | |
page_size: 100, | |
person_fields: 'names,emailAddresses' | |
) | |
response.connections.each do |connection| | |
puts connection.inspect | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment