This page documents all the methods and classes defined in the JavaScript client library.
Asynchronously loads the gapi libraries requested. Use this method to load the
gapi.client
library.
Arguments:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
libraries
|
string |
A colon (: ) separated list of gapi libraries. Ex:
"client:iframes" .
|
|||||||||||||||
callbackOrConfig
|
function|object |
Either:
|
Example:
gapi.load('client', { callback: function() { // Handle gapi.client initialization. initGapiClient(); }, onerror: function() { // Handle loading error. alert('gapi.client failed to load!'); }, timeout: 5000, // 5 seconds. ontimeout: function() { // Handle timeout. alert('gapi.client could not load in a timely manner!'); } });
Initializes the JavaScript client with API key, OAuth client ID, scope, and API discovery document(s).
Arguments:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args
|
object |
An object encapsulating the various arguments for this
method. Every argument is optional.
|
Returns:
Type | Description | |
---|---|---|
goog.Thenable
|
The return value is a Promise-like
goog.Thenable
object that resolves when all initializations, including setting the API key, loading
discovery documents, and initializing auth, are done.
|
Loads the client library interface to a particular API with
discovery document
URL or JSON object. Returns a Promise-like
goog.Thenable
object that resolves when the API interface is loaded. The loaded API interface will be in
the form
gapi.client.api.collection.method
. For example, the Moderator
API would create methods like
gapi.client.moderator.series.list
.
Arguments:
Name | Type | Description | ||
---|---|---|---|---|
urlOrObject
|
string | object | The Discovery Document URL or parsed Discovery Document JSON object (Example). |
Returns:
Type | Description | |
---|---|---|
goog.Thenable
|
The return value is a Promise-like
goog.Thenable object that resolves when the API interface is loaded.
|
Deprecated. Please load APIs with discovery documents.
Loads the client library interface to a particular API. If a callback is not provided, a
goog.Thenable
is returned. The loaded API interface will be in the form
gapi.client.api.collection.method
. For example, the Moderator
API would create methods like
gapi.client.moderator.series.list
.
Arguments:
Name | Type | Description | ||
---|---|---|---|---|
name
|
string | The name of the API to load. | ||
version
|
string | The version of the API to load. | ||
callback
|
function |
(optional) the function that is called once the API
interface is loaded. If not provided, a
goog.Thenable is returned.
|
Sets the API key for the application, which can be found in the Developer Console. Some APIs require this to be set in order to work.
Arguments:
Name | Type | Description | ||
---|---|---|---|---|
apiKey
|
string | The API key to set. |
Sets the authentication token to use in requests.
Arguments:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
tokenObject
|
object |
An object containing the access_token to use in API requests.
|
Creates a HTTP request for making RESTful requests.
Arguments:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
args
|
object |
An object encapsulating the various arguments for this
method. The path is required, the rest are optional.
The values are described in detail below.
|
Returns:
Type | Description | |
---|---|---|
gapi.client.Request | undefined
|
The returned gapi.client.Request object implements
goog.Thenable and can be used like a Promise that
fulfills with the response object or rejects with a reason object.
|
An object encapsulating an HTTP request. This object is not
instantiated directly, rather it is returned by gapi.client.request
.
There are two ways to execute a request. We recommend that you treat the object as a promise
and use the then
method, but you can also use the execute
method
and pass in a callback.
For more information about using promises, see Using Promises.
Executes the request and runs the supplied callback on response.
Arguments:
Name | Type | Description | ||
---|---|---|---|---|
callback(jsonResp,rawResp)
|
function |
The callback function which executes when the request
succeeds or fails. jsonResp contains the
response parsed as JSON. If the response is not JSON,
this field will be false .
rawResp is the HTTP response. It is JSON,
and can be parsed to an object which includes
body , headers ,
status , and statusText
fields.
|
Creates a batch object for batching individual requests.
Returns:
Type | Description | |
---|---|---|
gapi.client.Batch | undefined
|
The returned gapi.client.Batch implements
goog.Thenable interface and can be used like a Promise that fulfills with
a batch response object and rejects with a reason object.
|
Represents an HTTP Batch operation. Individual HTTP requests are
added with the add
method and the batch can be
executed using then
or execute
. We recommend that you treat the
batch object as a promise and use then
. This class defines the following
methods:
Adds a gapi.client.Request
to the batch.
Arguments:
Name | Type | Description | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
request
|
gapi.client.Request | The HTTP request to add to this batch. This parameter is required. | |||||||||||
opt_params
|
Object |
Optional extra parameters for this batch entry.
Accepted fields are id and
callback :
|
For more information about using promises, see Using Promises.
Executes all requests in the batch. The supplied callback is executed on success or failure.
Name | Type | Description |
---|---|---|
callback(responseMap,
rawBatchResponse)
|
function |
The callback to execute when the batch returns.
responseMap is an ID-response map of each
requests response. rawBatchResponse is the
same response, but as an unparsed JSON-string.
|