在谷歌请求对象的操作中,我有accessToken,我通过帐户链接设置
{
"user": {
"userId": "user_id",
"accessToken": "access_token",
"locale": "en-US",
"lastSeen": "2018-06-05T09:52:35Z",
"userStorage": "{\"data\":{}}"
},
etc
我的firebase功能允许在触发意图时在Firebase数据库中查找值。
import * as admin from 'firebase-admin'
import * as functions from 'firebase-functions'
import { dialogflow } from 'actions-on-google'
const dialogApp = dialogflow();
dialogApp.intent("request_value", async (conv, {devices}) => {
console.log(devices);
let device_name = devices;
const snapshot = await admin.database().ref(`/system/ecofarmTest/component/${device_name}/data`).orderByChild("timestamp").limitToFirst(1).once('value');
snapshot.forEach(function(childSnapshot) {
console.log("Test child timestamp " + childSnapshot.val().timestamp)
console.log("Test child value " + childSnapshot.val().value)
const value_object = childSnapshot.val();
conv.ask(`The ${device_name} is ${value_object.value}.\nWould you like to check anything else?`);
return;
})
});
export const receiveAssistantRequest = functions.https.onRequest(dialogApp);
在API更改之前,我新了如何访问请求对象。但是现在,如何访问请求对象以获取accessToken?
答案 0 :(得分:2)
完成帐户关联后,您可以使用
访问access_tokenconv.user.access.token
答案 1 :(得分:1)
我找到了办法:
let access_token = conv.request.user.accessToken