node.js - Google prediction API v1.6 - How can I make server to server call? -


i'm experimenting google prediction api v1.6. i've followed getting started section, , created model using explorer api.

now, model ready , prediction results explorer satisfying.

now when i'm trying move forward (using nodejs), i'm lost ... i've looked @ this library couldn't figure out how make call prediction.trainedmodels.predict without client side consent screen.

faced same problem, here found:

1 you'll need create service account.

  • go google developers console
  • click apis & auth > credentials
  • add credentials service account, download generated service account's public/private key

recommendation: application can complete these tasks either using google apis client library language, or directly interacting oauth 2.0 system using http. however, mechanics of server-to-server authentication interactions require applications create , cryptographically sign json web tokens (jwts), , it's easy make serious errors can have severe impact on security of application.

for reason, encourage use libraries, such google apis client libraries, abstract cryptography away application code.

  1. in server code should follow steps
    • create json web token (jwt, pronounced "jot"), includes header, claim set, , signature.
    • request access token google oauth 2.0 authorization server.
    • handle json response authorization server returns.

use google api node js lib handle auth more easy.

var key = require('path/to/key.json'); var jwtclient = new google.auth.jwt(key.client_email, null, key.private_key, [scope1, scope2], null);     jwtclient.authorize(function(err, tokens) {   if (err) {        console.log(err);        return;       }       // make authorized request list drive files.    drive.files.list({ auth: jwtclient }, function(err, resp) {        // handle err , response       }); }); 

Comments

Popular posts from this blog

php - Invalid Cofiguration - yii\base\InvalidConfigException - Yii2 -

How to show in django cms breadcrumbs full path? -

ruby on rails - npm error: tunneling socket could not be established, cause=connect ETIMEDOUT -