Google上的操作,Oauth帐户关联

时间:2019-03-20 17:33:10

标签: oauth-2.0 dialogflow actions-on-google account-linking

我一直试图将助手操作连接到我的后端服务器 我正在使用自己的Oauth服务器,并按照上的说明进行操作 https://developers.google.com/actions/identity/oauth2?oauth=code 我正在将actions_intent_Sign_in用于我的dialogflow事件意图(例如https://actions-on-google.github.io/actions-on-google-nodejs/classes/conversation_helper.signin.html) 当我使用操作登录时,将登录窗口显示到服务器上,进行帐户链接,并且可以看到我在服务器上生成了令牌,但在(conv.user.access.token中找不到令牌)

这是我使用“ google sdk上的操作”

的意图的代码

'use strict';
var _ = require('lodash');

var path = require('path')
var express = require('express')
var http = require('http')
const bodyParser = require('body-parser');


var expressApp = express().use(bodyParser.json());

var server = http.createServer(expressApp).listen(3000)

const {
    dialogflow,
    SignIn
} = require('actions-on-google');


const app = dialogflow({
    debug: true,
    clientId: '7b4a6dfc-4b35-11e9-8646-d663bd873d93'
});

app.intent('Start Sign-in', conv => {
    conv.ask(new SignIn());
});

app.intent('Get Sign-in', (conv, params, signin) => {
    console.log("get sign in ");
    console.log(JSON.stringify(signin));
    if (signin.status === 'OK') {
        const access = conv.user.access.token 
        console.log("the access token is " + access);
        conv.ask('Great, thanks for signing in! What do you want to do next?');
    } else {
        conv.ask('I wont be able to save your data, but what do you want to do next?.');
    }
});

,响应返回为

{"@type":"type.googleapis.com/google.actions.v2.SignInValue","status":"OK"}
the access token is undefined
Response {
  "status": 200,
  "headers": {
    "content-type": "application/json;charset=utf-8"
  },
  "body": {
    "payload": {
      "google": {
        "expectUserResponse": true,
        "richResponse": {
          "items": [
            {
              "simpleResponse": {
                "textToSpeech": "Great, thanks for signing in! What do you want to do next?"
              }
            }
          ]
        }
      }
    }
  }
}

conv的用户对象只有此数据

"user": {
    "raw": {
      "lastSeen": "2019-03-20T12:46:23Z",
      "locale": "en-US",
      "userId": "okdhyeGSk5tofgLjEepIUrA6mmewCESY8MjklZRPvQJgv6-uybfPobwdfgtrGZJ3bE2sM9ninhst"
    },
    "storage": {},
    "_id": "okdhyeGSk5tofgLjEepIUrA6mmewCESY8MjklZRPvQJgv6-uybfPobwdfgtrGZJ3bE2sM9ninhst",
    "locale": "en-US",
    "permissions": [],
    "last": {
      "seen": "2019-03-20T12:46:23.000Z"
    },
    "name": {},
    "entitlements": [],
    "access": {},
    "profile": {}
  }

我不知道在哪里可以找到访问/刷新令牌,或者是否有要求从我错过的oauth服务器发送帖子

1 个答案:

答案 0 :(得分:0)

所以最终我在Google支持团队的Actions的帮助下设法使其工作

问题是即使我将AoG和dialogflow代理连接到同一帐户,我还是在另一个标签中登录了另一个Google帐户

使用隐身窗口尝试了所有方法,并且有效