<commit_before># google-api-nodejs-client [alpha]

[![Build Status](https://travis-ci.org/google/google-api-nodejs-client.png)](https://travis-ci.org/google/google-api-nodejs-client)

`google-api-nodejs-client` is the Google's officially supported
[node.js](http://nodejs.org/) client
library for accessing Google APIs, it also supports authorization and
authentication with OAuth 2.0.

**Note**: This library is currently in *alpha* status, meaning that we can make
changes in the future that *may not be compatible* with the previous versions.

## Installation

The library is distributed on `npm`. In order to add it as a dependency,
run the following command:

    $ npm install googleapis

## Guide

Dynamically load any Google API and start making requests:

    var googleapis = require('googleapis');

    googleapis.load('urlshortener', 'v1', function(err, client) {
      var params = { shortUrl: 'http://goo.gl/DdUKX' };
      var request = client.urlshortener.url.get(params);
      request.execute(function (err, response) {
        console.log('Long url is', response.longUrl);
      });
    });

Supported APIs are listed on
[Google APIs Explorer](https://developers.google.com/apis-explorer).

### API Clients

Client libraries are generated during runtime by metadata provided by Google
APIs Discovery Service. Metadata provided by Discovery Service is not cached,
but requested each time you load a client. We're making changes to improve the
situation for short-lived node processes. Below, there is an example of loading
a client for [URL Shortener API](https://developers.google.com/url-shortener/).

    googleapis.load('urlshortener', 'v1', function(err, client) {
      if (!err) {
        console.log('Client is loaded successfully');
      }
    });

Alternatively, you may like to configure the client to append an API key to all
requests you are going to make. Once you load a client library, you can set an
API key:

     googleapis.load('urlshortener', 'v1', function(err, client) {
       client.withApiKey('YOUR API KEY HERE');
       // make requests
     });

To learn more about API keys, please see the [documentation](https://developers.google.com/console/help/#UsingKeys).

### Requests

Following sample loads a client for URL Shortener and retrieves the long url
of the given short url:

    googleapis.load('urlshortener', 'v1', function(err, client) {
      // ...
      client
        .urlshortener
        .url
        .get({ shortUrl: 'http://goo.gl/DdUKX' })
        .execute(function(err, result) {
          // result.longUrl contains the long url.
        });
    });


### Batch requests

You can combine multiple requests in a single one by using batch requests.

    googleapis.load('urlshortener', 'v1', function(err, client) {
      // ...
      var request1 =
          client.urlshortener.url.get({ shortUrl: 'http://goo.gl/DdUKX' });
      var request2 =
          client.urlshortener.url.insert(null, { longUrl: 'http://goo.gl/A5492' });
      // create from raw action name
      var request3 = client.newRequest('urlshortener.url.list');

      client
        .newBatchRequest()
        .add(request1)
        .add(request2)
        .add(request3)
        .execute(function(err, results) {

        });
    });

### Authorization and Authentication

This client comes with an OAuth2 client allows you to retrieve an access token and
refreshes the token and re-try the request seamlessly if token is expired. The
basics of Google's OAuth 2.0 implementation is explained on
[Google Authorization and Authentication
documentation](https://developers.google.com/accounts/docs/OAuth2Login).

A complete sample application that authorizes and authenticates with OAuth2.0
client is available at `examples/oauth2.js`.

#### Consent Page Url

In order to ask for permissions from user to retrieve an access token, you
should redirect them to a consent page. In order to create a consent page
URL:

    var googleapis = require('googleapis'),
        OAuth2Client = googleapis.OAuth2Client;<commit_msg>Fixing doc with multiple discovery related features.<commit_after># google-api-nodejs-client [alpha]

[![Build Status](https://travis-ci.org/google/google-api-nodejs-client.png)](https://travis-ci.org/google/google-api-nodejs-client)

`google-api-nodejs-client` is the Google's officially supported
[node.js](http://nodejs.org/) client
library for accessing Google APIs, it also supports authorization and
authentication with OAuth 2.0.

**Note**: This library is currently in *alpha* status, meaning that we can make
changes in the future that *may not be compatible* with the previous versions.

## Installation

The library is distributed on `npm`. In order to add it as a dependency,
run the following command:

    $ npm install googleapis

## Guide

### Discover APIs

Dynamically load Google APIs and start making requests:

    var googleapis = require('googleapis');

    googleapis
        .discover('urlshortener', 'v1')
        .discover('plus', 'v3')
        .execute(function(err, client) {
      var params = { shortUrl: 'http://goo.gl/DdUKX' };
      var req1 = client.urlshortener.url.get(params);
      req1.execute(function (err, response) {
        console.log('Long url is', response.longUrl);
      });
      
      var req2 = client.plus.people.get({ userId: '+BurcuDogan' });
      req2.execute();
    });

Supported APIs are listed on
[Google APIs Explorer](https://developers.google.com/apis-explorer).

### API Client

Client libraries are generated during runtime by metadata provided by Google
APIs Discovery Service. Metadata provided by Discovery Service is not cached,
but requested each time you load a client. We're making changes to improve the
situation for short-lived node processes. Below, there is an example of loading
a client for [URL Shortener API](https://developers.google.com/url-shortener/).

    googleapis
         .discover('urlshortener', 'v1')
         .execute(function(err, client) {
       // make requests
     });

Alternatively, you may like to configure the client to append an API key to all
requests you are going to make. Once you load a client library, you can set an
API key:

     googleapis
         .discover('urlshortener', 'v1')
         .withApiKey('YOUR API KEY HERE')
         .execute(function(err, client) {
       // make requests
     });

To learn more about API keys, please see the [documentation](https://developers.google.com/console/help/#UsingKeys).

### Requests

Following sample loads a client for URL Shortener and retrieves the long url
of the given short url:

     googleapis
         .discover('urlshortener', 'v1')
         .execute(function(err, client) {
       client.urlshortener.url.get({ shortUrl: 'http://goo.gl/DdUKX' })
           .execute(function(err, result) {
             // result.longUrl contains the long url.
           });
     });

### Batch requests

You can combine multiple requests in a single one by using batch requests.

    var request1 =
        client.plus.people.get({ userId: '+BurcuDogan' });
    var request2 =
        client.urlshortener.url.insert(null, { longUrl: 'http://goo.gl/A5492' });
    // create from raw action name
    var request3 = client.newRequest('urlshortener.url.list');

    client
      .newBatchRequest()
      .add(request1)
      .add(request2)
      .add(request3)
      .execute(function(err, results) {

      });

### Authorization and Authentication

This client comes with an OAuth2 client allows you to retrieve an access token and
refreshes the token and re-try the request seamlessly if token is expired. The
basics of Google's OAuth 2.0 implementation is explained on
[Google Authorization and Authentication
documentation](https://developers.google.com/accounts/docs/OAuth2Login).

A complete sample application that authorizes and authenticates with OAuth2.0
client is available at `examples/oauth2.js`.

#### Consent Page Url

In order to ask for permissions from user to retrieve an access token, you
should redirect them to a consent page. In order to create a consent page
URL:

    var googleapis = require('googleapis'),
        OAuth2Client = googleapis.OAuth2Client;
{'fraction_non_alphanumeric': 0.10354090354090355, 'fraction_numerical': 0.006837606837606838, 'mean_word_length': 3.347664543524416, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 12, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1806874', 'n_tokens_mistral': 2347, 'n_tokens_neox': 2252, 'n_words': 827}