I have setup a new project to access my GSuite account users. When I run my code it gives 401 - 'Login required'.
I have granted 'Domain wide authority' to the account with the required scopes.
The code that I am using is:
def authorize
authorizer = Google::Auth::ServiceAccountCredentials.make_creds(
json_key_io: File.open('path-to-file.json'),
scope: "https://www.googleapis.com/auth/admin.directory.user.readonly")
authorizer.sub = 'GSuite admin email'
authorizer.fetch_access_token!
end
service = Google::Apis::AdminDirectoryV1::DirectoryService.new
service.authorization = authorize
response = service.list_users
The project is setup on my personal google developer account.
Any ideas why this is happening and how I can fix it?
Are your running on windows? Do you have Ruby 2? I think you are using old code.
link for code