Reputation:
I'm reading this getting started document:
https://github.com/google/google-api-javascript-client/blob/master/docs/start.md
In Option1, the following code is written:
gapi.client.people.people.get({
'resourceName': 'people/me',
'requestMask.includeField': 'person.names'
})
Why .people.people
? I want to know the details of this syntax. If I use google drive API, do I write gapi.client.drive.drive.get
?
Upvotes: 0
Views: 1044
Reputation: 116958
To answer this question lets start with the Discovery services api
The Discovery API provides a list of Google APIs for retrieving a machine-readable "Discovery document" metadata for each API.
The reason we are looking at this is because the Google apis js client library which you are using gapi was generated using the discovery services api. apis-client-generator
Then lets look at the discovery dock for people api
If you check under resources you get
Then each resource has a group of methods under and the people resource has a method called get.
So people.people.get
is actually {API}.{resource}.{method}
This is just how google chose to build up the API.
Now the google drive api also has a group of resources
There is a method called gapi.client.drive.drives.get Which is drive api, drives resource, get method which will return a drives resource.
If your actually after files then its probably more like gapi.client.drive.files.get Which is drive api, files resource, file get method which would return a file resource.
Upvotes: 3
Reputation: 7179
From the API Discovery Document:
For each method defined in the API Discovery Document, a corresponding method is constructed on the
gapi.client
object.For example, The People API's methods are under
gapi.client.people
.The People API has the methods
people.get
andpeople.connections.list
.[T]he generated methods can be called as follows:
gapi.client.people.people.get(...)
gapi.client.people.people.connections.list(...)
You can view API Methods on APIs Explorer.
So .people.people
means:
Using the
People API
-equivalent methodpeople
, call thepeople.get(...)
method.
To use the Drive API v3, you would query against gapi.client.drive
with your method name. For example, gapi.client.drive.channels.stop(...)
.
An important note from this answer: you must load the Drive API before using it.
gapi.client.load('drive', 'v3', callback);
Upvotes: 0