我正在创造一种智能的家庭整合。我要对设备步骤进行测试--尝试登录到一个帐户以添加设备。
我已经设置了助手来检索OAuth令牌:

这是可行的-在我的测试设备上,我可以打开:设置>家庭控制>添加设备,并看到我的项目。然后,我也可以向OAuth登录。然而,下一步是谷歌,然后应该“助手发送一个action.devices.SYNC意图给你的实现”
从医生那里:
用户使用Google应用程序设置他们的设备,以验证您的云服务,助手将收到一个OAuth令牌。此时,助手向您发送一个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我已经检查了云功能日志,上面的实现称为。然而,文档中说它会发送一个action.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"
}发布于 2022-05-12 23:02:47
日志语句失败,因为不可能像云函数中那样访问request.requestId。如果您想要一个使用云函数和防火墙的端到端工作示例,可以按照智能家用洗衣机代码中的步骤操作。
https://stackoverflow.com/questions/49575739
复制相似问题