Access token undefined

别等时光非礼了梦想. 提交于 2019-12-25 01:51:02

问题


i am new to google actions and dialogflow. Here i want to send notification to google assistant. But i am getting

TypeError: Cannot read property 'access_token' of undefined

 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);
  });
});

来源:https://stackoverflow.com/questions/55371048/access-token-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!