From 80d3457530eca89f87814f1f07f26441051d2788 Mon Sep 17 00:00:00 2001 From: Tal Koren Date: Wed, 11 Mar 2020 14:10:55 +0200 Subject: [PATCH 01/19] Remove duplicated header --- docs/promises.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/promises.md b/docs/promises.md index 9de1612..9bae8b5 100644 --- a/docs/promises.md +++ b/docs/promises.md @@ -224,9 +224,6 @@ personFetcher.fetch('John'); ## Migrating from callbacks to promises -Migrating from callbacks to promises ------------------------------------- - The `result` parameter of the fulfilled promise value is equivalent to the first parameter in [`execute`](/api-client-library/javascript/reference/referencedocs#gapiclientRequestexecute)'s callback. To update your code to use promises, change your code as shown in the before and after examples below. The following example shows using a callback: @@ -249,4 +246,4 @@ gapi.client.request({ }).then(function(resp) { processResponse(resp.result); }); -``` \ No newline at end of file +``` From ce5a173a6ac487b5bbca9a141a3db0b83a7b75be Mon Sep 17 00:00:00 2001 From: Richard Michael Date: Fri, 22 May 2020 18:18:38 -0400 Subject: [PATCH 02/19] Make discussion consistent with sample code None of the provided examples perform `gapi.load('client:auth2', ...)` as indicated in the discussion. --- docs/samples.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/samples.md b/docs/samples.md index 3302c49..c420c80 100644 --- a/docs/samples.md +++ b/docs/samples.md @@ -48,13 +48,13 @@ The following sample demonstrates how to get "authorized" access to a Google API It's called "authorized" access because the user must give the application direct authorization to use personal data. Simple web-based applications using JavaScript usually get this authorization the way this example does: by displaying button for the user to click. This action triggers a call to a Google auth server, which pops up a standard authorization dialog. For details, see the [Authentication page](auth.md). -**Note:** Here we use `gapi.load('client:auth2', ...)` to load both the `client` module (for dealing with API requests) and the `auth2` module (for dealing with OAuth 2.0) upfront. The `gapi.client.init` fuction lazily loads `auth2` if it is needed. If you are sure your app needs auth, loading the two modules `'client:auth2'` together before you call `gapi.client.init` will save one script load request. +**Note:** You may use `gapi.load('client:auth2', ...)` to load both the `client` module (for dealing with API requests) and the `auth2` module (for dealing with OAuth 2.0) upfront. The `gapi.client.init` fuction lazily loads `auth2` if it is needed. If you are sure your app needs auth, loading the two modules `'client:auth2'` together before you call `gapi.client.init` will save one script load request. To make `gapi.client.init` set up OAuth correctly, you would have to assign the `clientID` variable the client ID generated when you registered your application (for instructions see [Integrating Google Sign-In into your web app](https://developers.google.com/identity/sign-in/web/sign-in)). The other parameter is `scope`, which in this case is just the scope for user profile permission. When the user clicks **Authorize**, the `gapi.auth2.getAuthInstance().signIn()` function is called, which shows user a popup window to let user authorize. Note that the `gapi.auth2.getAuthInstance().signIn()` can be only called from a user interaction context for most browsers (i.e. do not call it when your app starts, but call it in a button click handler). -**Note:** when you authorize your application using Oauth 2.0, you do not also need to set the API key as in the first example. However, it is a good practice to do so, in case your code ever expands to handle unauthorized requests. +**Note:** When you authorize your application using Oauth 2.0, you do not also need to set the API key as in the first example. However, it is a good practice to do so, in case your code ever expands to handle unauthorized requests. ## Loading the Library Asychronously From c54574d1d69746f567a6f91e34b5cf4de6779a93 Mon Sep 17 00:00:00 2001 From: Richard Michael Date: Fri, 22 May 2020 18:34:50 -0400 Subject: [PATCH 03/19] Update samples.md --- docs/samples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/samples.md b/docs/samples.md index c420c80..84c16cc 100644 --- a/docs/samples.md +++ b/docs/samples.md @@ -48,7 +48,7 @@ The following sample demonstrates how to get "authorized" access to a Google API It's called "authorized" access because the user must give the application direct authorization to use personal data. Simple web-based applications using JavaScript usually get this authorization the way this example does: by displaying button for the user to click. This action triggers a call to a Google auth server, which pops up a standard authorization dialog. For details, see the [Authentication page](auth.md). -**Note:** You may use `gapi.load('client:auth2', ...)` to load both the `client` module (for dealing with API requests) and the `auth2` module (for dealing with OAuth 2.0) upfront. The `gapi.client.init` fuction lazily loads `auth2` if it is needed. If you are sure your app needs auth, loading the two modules `'client:auth2'` together before you call `gapi.client.init` will save one script load request. +**Note:** The full sample uses `gapi.load('client:auth2', ...)` to load both the `client` module (for dealing with API requests) and the `auth2` module (for dealing with OAuth 2.0) upfront. The `gapi.client.init` fuction lazily loads `auth2` if it is needed. If you are sure your app needs auth, loading the two modules `'client:auth2'` together before you call `gapi.client.init` will save one script load request. To make `gapi.client.init` set up OAuth correctly, you would have to assign the `clientID` variable the client ID generated when you registered your application (for instructions see [Integrating Google Sign-In into your web app](https://developers.google.com/identity/sign-in/web/sign-in)). The other parameter is `scope`, which in this case is just the scope for user profile permission. From 821595185288044d2def1da4336798134f4108da Mon Sep 17 00:00:00 2001 From: Richard Michael Date: Fri, 22 May 2020 18:41:01 -0400 Subject: [PATCH 04/19] Use the literal text from the Google APIs console. Makes it easier for readers to follow along. --- docs/start.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/start.md b/docs/start.md index e7ebe12..ef87357 100644 --- a/docs/start.md +++ b/docs/start.md @@ -133,14 +133,14 @@ Google defines two levels of API access: #### To acquire an API key for simple access, do the following: -1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the API Console. +1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the "APIs & Services" console. 2. Click **Create credentials > API key** and select the appropriate key type. To keep your API keys secure, follow the [best practices for securely using API keys](https://support.google.com/cloud/answer/6310037). #### To acquire OAuth 2.0 credentials for authorized access, do the following: -1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the API Console. +1. Open the [Credentials page](https://console.developers.google.com/apis/credentials) in the "APIs & Services" console. 2. Click **Create credentials > OAuth client ID** and select the appropriate Application type. -For information about using OAuth 2.0 credentials, see the [Authentication](https://developers.google.com/api-client-library/javascript/features/authentication) page. \ No newline at end of file +For information about using OAuth 2.0 credentials, see the [Authentication](https://developers.google.com/api-client-library/javascript/features/authentication) page. From e96abcb554e2a5ce8d9d8d99095a11ab6ca1904b Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 8 Jun 2020 23:45:46 +0530 Subject: [PATCH 05/19] Updated link for API Discovery Document(s) --- docs/start.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/start.md b/docs/start.md index ef87357..801348b 100644 --- a/docs/start.md +++ b/docs/start.md @@ -8,7 +8,7 @@ You can use the JavaScript client library to interact with Google APIs, such as There are several ways to use the JavaScript client library to make API requests, but they all follow the same basic pattern: 1. The application loads the JavaScript client library. -2. The application initializes the library with API key, OAuth client ID, and [API Discovery Document(s)](https://developers.google.com/api-client-library/javascript/features/discovery). +2. The application initializes the library with API key, OAuth client ID, and [API Discovery Document(s)](https://github.com/google/google-api-javascript-client/blob/master/docs/discovery.md). 3. The application sends a request and processes the response. The following sections show 3 common ways of using the JavaScript client library. From e9e0d15dc91ca4b0477afd91fc8ba51b9f8b8fde Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Mon, 8 Jun 2020 23:50:53 +0530 Subject: [PATCH 06/19] Updated link for OAuth 2 authentication .md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 22a9d77..4048bca 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ developers. It offers simple, flexible access to many Google APIs. The JavaScript client library [supports these Google APIs](https://developers.google.com/apis-explorer/#p/). -The library supports [OAuth 2 authentication](https://developers.google.com/api-client-library/javascript/features/authentication). +The library supports [OAuth 2 authentication](https://github.com/google/google-api-javascript-client/blob/master/docs/auth.md). If you use TypeScript, you can install [`@types/gapi`](https://www.npmjs.com/package/@types/gapi) for autocompletion. From ef5a071d22f0e9d692f49420155a7883a892c670 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Tue, 9 Jun 2020 00:50:23 +0530 Subject: [PATCH 07/19] Update OAuth 2 authentication's relative link Update OAuth 2 authentication's doc link with relative url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4048bca..d015663 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ developers. It offers simple, flexible access to many Google APIs. The JavaScript client library [supports these Google APIs](https://developers.google.com/apis-explorer/#p/). -The library supports [OAuth 2 authentication](https://github.com/google/google-api-javascript-client/blob/master/docs/auth.md). +The library supports [OAuth 2 authentication](docs/auth.md). If you use TypeScript, you can install [`@types/gapi`](https://www.npmjs.com/package/@types/gapi) for autocompletion. From 945d206efa5a4c58e426a9d1e0a29ea5717774d2 Mon Sep 17 00:00:00 2001 From: Abhinav Sharma Date: Tue, 9 Jun 2020 00:54:40 +0530 Subject: [PATCH 08/19] Update API Discovery Document's relative link --- docs/start.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/start.md b/docs/start.md index 801348b..cb914a0 100644 --- a/docs/start.md +++ b/docs/start.md @@ -8,7 +8,7 @@ You can use the JavaScript client library to interact with Google APIs, such as There are several ways to use the JavaScript client library to make API requests, but they all follow the same basic pattern: 1. The application loads the JavaScript client library. -2. The application initializes the library with API key, OAuth client ID, and [API Discovery Document(s)](https://github.com/google/google-api-javascript-client/blob/master/docs/discovery.md). +2. The application initializes the library with API key, OAuth client ID, and [API Discovery Document(s)](discovery.md). 3. The application sends a request and processes the response. The following sections show 3 common ways of using the JavaScript client library. From e82ec061542ed461eff609e31c707f4a17ad2565 Mon Sep 17 00:00:00 2001 From: Dan Wood Date: Tue, 15 Sep 2020 18:52:19 +1000 Subject: [PATCH 09/19] Fix link to auth example Seems that the link forwarding is going to the wrong place. Fixed that. --- docs/start.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/start.md b/docs/start.md index cb914a0..4f12aea 100644 --- a/docs/start.md +++ b/docs/start.md @@ -15,7 +15,7 @@ The following sections show 3 common ways of using the JavaScript client library ### Option 1: Load the API discovery document, then assemble the request. -The following example assumes the user has already signed in. For a full example of how to sign in a user, see the [full auth sample](https://developers.google.com/api-client-library/javascript/samples/samples#authorizing-and-making-authorized-requests). +The following example assumes the user has already signed in. For a full example of how to sign in a user, see the [full auth sample](https://github.com/google/google-api-javascript-client/blob/master/docs/samples.md#authorizing-and-making-authorized-requests). ```html From ea2bce4c043e500301e9c6ad8dd00d35593a68db Mon Sep 17 00:00:00 2001 From: Piper Date: Sat, 24 Oct 2020 16:16:49 -0700 Subject: [PATCH 10/19] fix: casing typo --- samples/analytics/v3/hello_analytics_api_v3.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/analytics/v3/hello_analytics_api_v3.html b/samples/analytics/v3/hello_analytics_api_v3.html index e4cad88..731efe1 100644 --- a/samples/analytics/v3/hello_analytics_api_v3.html +++ b/samples/analytics/v3/hello_analytics_api_v3.html @@ -11,7 +11,7 @@

Hello Google Analytics API

This page demonstrates how to query the Google Analytics API version 3 using the - Google API Javascript Client Library.

+ Google API JavaScript Client Library.

The demo traverses the From a6ac3146b62784db046510c63cbeff70c7722c55 Mon Sep 17 00:00:00 2001 From: Dmytro Chumak Date: Sun, 25 Oct 2020 19:47:58 +0100 Subject: [PATCH 11/19] Fix discovery links in reference.md --- docs/reference.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/reference.md b/docs/reference.md index dd5c501..cdbf72f 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -147,7 +147,7 @@ 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). + API discovery document(s). If OAuth client ID and scope are provided, this function will load the gapi.auth2 module to perform OAuth. The gapi.client.init function can be run multiple times, such as to set up more APIs, to change API key, or initialize @@ -275,7 +275,7 @@ alert('gapi.client could not load in a timely manner!');

Loads the client library interface to a particular API with - discovery document + discovery document URL or JSON object. Returns a Promise-like goog.Thenable @@ -908,4 +908,4 @@ alert('gapi.client could not load in a timely manner!'); - \ No newline at end of file + From 5b0d5e0ac6b1042ac75ece9ac1ba545f7dd1002c Mon Sep 17 00:00:00 2001 From: David van der Bokke Date: Mon, 5 Apr 2021 09:40:14 -0700 Subject: [PATCH 12/19] Update batch documentation --- docs/batch.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/batch.md b/docs/batch.md index eae199b..a612633 100644 --- a/docs/batch.md +++ b/docs/batch.md @@ -7,12 +7,12 @@ The JavaScript client library supports batching HTTP requests to make multiple A The JavaScript client library defines an object called `Batch`. You can start by instantiating this object: ```js -var batch = gapi.client.newBatch(); +const batch = gapi.client.newBatch(); ``` ## Adding requests to the batch -Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_params--) method to add individual HTTP requests. The `add` method supports one optional parameter: +Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_params--) method to add individual HTTP requests. Only requests created via [discovery](discovery.md) should be added to a batch. The `add` method supports one optional parameter: @@ -49,19 +49,18 @@ Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_p Example: ```js -var searchRequest = function(name) { - return gapi.client.request({ - 'path': 'plus/v1/people', - 'params': {'query': name} - }); -}; -var searchAlvin = searchRequest('Alvin'); -var searchSimon = searchRequest('Simon'); +const getMe = gapi.client.people.people.get({ + 'resourceName': 'people/me' +}); + +const getYou = gapi.client.people.people.get({ + 'resourceName': 'people/you' +}); // Adding just the request -batch.add(searchAlvin); +batch.add(getMe); // Adding the request with an ID -batch.add(searchSimon, {'id': 'searchSimon'}); +batch.add(getYou, {'id': 'getYou'}); ``` ## Executing a batch From 72b7a3ebae91e725f0c7a487618b2b0c7e552e46 Mon Sep 17 00:00:00 2001 From: David van der Bokke Date: Mon, 5 Apr 2021 09:40:14 -0700 Subject: [PATCH 13/19] Update batch documentation Update batch.md with discovery generated API sample Remove httpBatch.html sample since it is duplicative of batch.md and out of date(plus API does not exist anymore) --- docs/batch.md | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/docs/batch.md b/docs/batch.md index eae199b..a612633 100644 --- a/docs/batch.md +++ b/docs/batch.md @@ -7,12 +7,12 @@ The JavaScript client library supports batching HTTP requests to make multiple A The JavaScript client library defines an object called `Batch`. You can start by instantiating this object: ```js -var batch = gapi.client.newBatch(); +const batch = gapi.client.newBatch(); ``` ## Adding requests to the batch -Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_params--) method to add individual HTTP requests. The `add` method supports one optional parameter: +Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_params--) method to add individual HTTP requests. Only requests created via [discovery](discovery.md) should be added to a batch. The `add` method supports one optional parameter:
@@ -49,19 +49,18 @@ Use the `Batch` object's [`add`](reference.md#----gapiclientbatchaddrequestopt_p Example: ```js -var searchRequest = function(name) { - return gapi.client.request({ - 'path': 'plus/v1/people', - 'params': {'query': name} - }); -}; -var searchAlvin = searchRequest('Alvin'); -var searchSimon = searchRequest('Simon'); +const getMe = gapi.client.people.people.get({ + 'resourceName': 'people/me' +}); + +const getYou = gapi.client.people.people.get({ + 'resourceName': 'people/you' +}); // Adding just the request -batch.add(searchAlvin); +batch.add(getMe); // Adding the request with an ID -batch.add(searchSimon, {'id': 'searchSimon'}); +batch.add(getYou, {'id': 'getYou'}); ``` ## Executing a batch From 8c955154dc578eb880481cfb0a8b38bbdbfba0ba Mon Sep 17 00:00:00 2001 From: Niel Markwick Date: Fri, 25 Feb 2022 12:17:03 +0100 Subject: [PATCH 14/19] Add clarification for Chrome Extensions Manifest v3 GAPI is not supported for Chrome Extensions with Manifest v3 due to the no remotely hosted code requirement. Updated docs to reflect this --- docs/faq.md | 5 +++++ docs/start.md | 2 ++ 2 files changed, 7 insertions(+) diff --git a/docs/faq.md b/docs/faq.md index d04e243..a684f19 100644 --- a/docs/faq.md +++ b/docs/faq.md @@ -29,3 +29,8 @@ The JavaScript client library does not directly support logging the user out of Since logging out of the application also logs the user out of the Google account, it is not recommended to log the user out unless the user requests this explicitly. For a workaround that allows your application to log the user out programatically, see [this topic](https://groups.google.com/forum/?fromgroups=#!topic/google-api-javascript-client/PCs8xXV4wxk) in the JavaScript client library discussion group. + + +### Is it possible to use the JavaScript client library in a Chrome Extension? + +Chrome Extensions using Manifest v3 do not allow [remotely hosted code](https://developer.chrome.com/docs/extensions/mv3/intro/mv3-overview/#remotely-hosted-code), so the Javascript client library cannot be used in this case. diff --git a/docs/start.md b/docs/start.md index 4f12aea..9377fb8 100644 --- a/docs/start.md +++ b/docs/start.md @@ -85,6 +85,8 @@ Google APIs support [CORS](http://www.w3.org/TR/cors/). If your application need The JavaScript client library works with the same browsers supported by [Google Apps](https://support.google.com/a/answer/33864) except that mobile browsers are currently not fully supported. It only works within HTML documents with a `` element served using the `https` _(preferred)_ and `http` protocols. However, `