Socket error when calling Google API through node client

The code below calls the Google Analytics Reporting API using the client version of Google nodejs 0.7 here . It returns an error socket hang upon some executions, but not always. Will this be a mistake on shutting down a Google server? Is there an easy way to debug? BTW I make several calls in sequence, not sure if this is caused by speed limits.

gapi = require "googleapis"
authClient = new gapi.auth.JWT(
  config.ga.clientEmail,
  config.ga.privateKeyPath,
  null,
  [config.ga.scopeUri]
)

authPromise = new Promise (resolve, reject) ->
  authClient.authorize (err, token) ->
      resolve token
    return
  return

authPromise.then ->
  gapi.discover('analytics', 'v3')
    .withAuthClient(authClient)
    .execute (err, client) ->
      ...
+4
source share
1 answer

The error appeared after the client started successfully: client.analytics.data.ga.get(queryObj).execute (err, result) -> ....

, API, , .discover , client , .discover client s. , , . client, . :

gapi = require "googleapis"
authClient = new gapi.auth.JWT(
  config.ga.clientEmail,
  config.ga.privateKeyPath,
  null,
  [config.ga.scopeUri]
)

authPromise = new Promise (resolve, reject) ->
  authClient.authorize (err, token) ->
    gapi.discover('analytics', 'v3').withAuthClient(authClient).execute (err, client) ->
      resolve client
      return
    return
  return

authPromise.then (client) ->
  client.analytics.data.ga.get(queryObj).execute (err, result) ->
+1

Source: https://habr.com/ru/post/1544100/


All Articles