我正在创建一个智能家居集成。我正在测试设备步骤 - 尝试登录帐户以添加设备。
https://developers.google.com/actions/smarthome/#syncing_devices
我已经设置了助手来检索 OAuth 令牌:
这有效 - 在我的测试设备上我可以打开:设置 > 家庭控制 > 添加设备并查看我的项目。然后我也可以使用 OAuth 登录。然而下一步是谷歌然后应该“助手发送一个action.devices.SYNC意图到你的履行”
从文档:
用户使用 Google Assistant 应用程序设置他们的设备以对您的云服务进行身份验证,并且 Assistant 会收到 OAuth 令牌。此时,Assistant 会向您的实现发送一个 action.devices.SYNC 意图,以从您的云基础架构中检索用户设备和功能的初始列表。
履行设置正确:
我的实现看起来像这样:
exports.helloWorld = functions.https.onRequest((request, response) => {
const requestId = request.requestId;
if(request.inputs == null) {
console.log("unexpected request " + util.inspect(request, false, null));
console.log("unexpected request id " + requestId);
response.send(400);
return;
}
const userId = request.get("Authorization");
... etc do other stuff then return correct response as a 200
我检查了云功能日志并调用了上述实现。但是,文档说它会发送 aaction.devices.SYNC intent
而它不会。(因此永远不会超过第一个if
陈述)。
它发送了一些我不认识的东西(而且我没有看到我应该认识的文件):
(每个请求都应该有一个请求 ID - 而这个没有request id undefined
:)
有什么想法吗?
从评论中,这里是堆栈驱动程序日志:
{
insertId: "000000-751089a4-XXXX-XXXX-XXXX-f6a11a39b4d5"
labels: {
execution_id: "vXXXXsnaopim"
}
logName: "projects/XXXXX/logs/cloudfunctions.googleapis.com%2Fcloud-functions"
receiveTimestamp: "2018-03-29T13:44:56.577854174Z"
resource: {
labels: {
function_name: "helloWorld"
project_id: "XXXXX"
region: "us-central1"
}
type: "cloud_function"
}
severity: "INFO"
textPayload: "unexpected request IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: true,
endEmitted: true,
reading: false,
sync: false,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: false,
domain: null,
_events: {},
_eventsCount: 0,
_maxListeners: undefined,
socket:
Socket {
connecting: false,
_hadError: false,
_handle:
TCP {
bytesRead: 917,
_externalStream: {},
fd: 12,
reading: true,
owner: [Circular],
onread: [Function: onread],
onconnection: null,
writeQueueSize: 0,
_consumed: true },
_parent: null,
_host: null,
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: false,
endEmitted: false,
reading: true,
sync: false,
needReadable: true,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
defaultEncoding: 'utf8',
ranOut: false,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
domain: null,
_events:
{ end:
[ { [Function: g] listener: [Function: onend] },
[Function: socketOnEnd] ],
finish: [Function: onSocketFinish],
_socketEnd: [Function: onSocketEnd],
drain: [ [Function: ondrain], [Function: socketOnDrain] ],
timeout: [Function],
error: [ [Function: socketOnError], [Function: onevent] ],
close:
[ [Function: serverSocketCloseListener],
[Function: onServerResponseClose],
[Function: onevent] ],
data: [Function: socketOnData],
resume: [Function: onSocketResume],
pause: [Function: onSocketPause] },
_eventsCount: 10,
_maxListeners: undefined,
_writableState:
WritableState {
objectMode: false,
highWaterMark: 16384,
needDrain: false,
ending: false,
ended: false,
finished: false,
decodeStrings: false,
defaultEncoding: 'utf8',
length: 0,
writing: false,
corked: 0,
sync: true,
bufferProcessing: false,
onwrite: [Function],
writecb: null,
writelen: 0,
bufferedRequest: null,
lastBufferedRequest: null,
pendingcb: 0,
prefinished: false,
errorEmitted: false,
bufferedRequestCount: 0,
corkedRequestsFree: CorkedRequest { next: null, entry: null, finish: [Function] } },
writable: true,
allowHalfOpen: true,
destroyed: false,
_bytesDispatched: 0,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server:
Server {
domain: null,
_events:
{ request:
{ [Function: app]
domain: undefined,
_events: { mount: [Function: onmount] },
_maxListeners: undefined,
setMaxListeners: [Function: setMaxListeners],
getMaxListeners: [Function: getMaxListeners],
emit: [Function: emit],
addListener: [Function: addListener],
on: [Function: addListener],
prependListener: [Function: prependListener],
once: [Function: once],
prependOnceListener: [Function: prependOnceListener],
removeListener: [Function: removeListener],
removeAllListeners: [Function: removeAllListeners],
listeners: [Function: listeners],
listenerCount: [Function: listenerCount],
eventNames: [Function: eventNames],
init: [Function],
defaultConfiguration: [Function],
lazyrouter: [Function],
handle: [Function],
use: [Function: use],
route: [Function],
engine: [Function],
param: [Function],
set: [Function],
path: [Function],
enabled: [Function],
disabled: [Function],
enable: [Function],
disable: [Function],
acl: [Function],
bind: [Function],
checkout: [Function],
connect: [Function],
copy: [Function],
delete: [Function],
get: [Function],
"
timestamp: "2018-03-29T13:44:50.294Z"
}