Search code examples
javascriptjsonvue-resourcegoogle-directory-apigoogle-apis-explorer

Is it possible to get a list of users from Directory API using only api key in a string?


I keep getting in to a loop of only seeing google's OAUTH documentation when searching for this but I don't want any user interaction. Maybe it's not possible. I want to do something like the code below in a http GET like you do with the maps API and receive a JSON reply

https://www.googleapis.com/admin/directory/v1/users?domain=MYDOMAIN&maxResults=200&key=MYAPIKEY

When I try something like the above I get 401 login required. I'm using vue-resource to make the request if that is relevant.

If it is possible could someone post an example of a correctly formatted request?


Solution

  • Based on the documentation available at https://developers.google.com/admin-sdk/directory/v1/guides/manage-users you should be able to do this with a simple get request however it MUST be authorized with OAUTH 2.

    As stated at https://developers.google.com/admin-sdk/directory/v1/guides/authorizing "Your application must use OAuth 2.0 to authorize requests. No other authorization protocols are supported."

    I haven't used vue-resource before however I know that the Chrome plugin Postman has an authorization option to target OAUTH2.0 which should be a good place to start and perform a quick proof of concept.

    Once you have the proof of concept working and understand how to interact with OAUTH you can look at implementing it in your app.