Токен доступа не определен - PullRequest
0 голосов
/ 27 марта 2019

Я новичок в действиях и диалогах Google.Здесь я хочу отправить уведомление помощнику Google.Но я получаю

TypeError: Невозможно прочитать свойство 'access_token' из неопределенного

 const { google } = require('googleapis');
 const key = require('./myapp.json');

let jwtClient = new google.auth.JWT(
 key.client_email, null, key.private_key,
 ['https://www.googleapis.com/auth/actions.fulfillment.conversation'],
 null
 );

jwtClient.authorize((err, tokens) => {
let notif = {
    userNotification: {
        title: "message",
    },
    target: {
        userId: 'xxxyyyzzzz',
        intent: 'intent_name',
        locale: 'en-US'
    },
};

request.post('https://actions.googleapis.com/v2/conversations:send', {
    'auth': {
        'bearer': tokens.access_token,
    },
    'json': true,
    'body': { 'customPushMessage': notif },
}, (err, httpResponse, body) => {
    console.log(body);
    console.log(httpResponse.statusCode + ': ' + httpResponse.statusMessage);
  });
});
...