0

有没有人能够让 google-api-nodejs-client 成功插入片刻?

无论我尝试什么,我都会收到一个通用的 400“无效值”错误,但无法缩小无效值的范围,因为API Explorer也不起作用。

是因为缺少 data-requestvisibleactions 参数吗?我正在使用 passport.jsrequire('passport-google-oauth').OAuth2Strategy来处理 oauth 访问,这部分工作正常,但我不知道如何将 requestvisibleactions 合并到 oauth 请求流中,因为这绝对不是来自客户端表单。

这是我正在尝试做的一个片段(使用最新版本的googleapisv1.0.2):

var google = require('googleapis')
var auth = new google.auth.OAuth2()
auth.setCredentials({
  'access_token': user.token
})

google.plus('v1').moments.insert({
  collection: 'vault',
  userId: 'me',
  debug: true,
  resource: {
    type: "http://schemas.google.com/AddActivity",
    target: {
      type: "http://schema.org/CreativeWork",
      url: "...omitted...",
      image: "...omitted...",
      description: "test",
      name: "test"
    }
  },
  auth: auth
}, function (err, response) {
  if (err) {
    console.error(err)
    res.send(err.code, err)
  } else {
    console.log(response)
    res.send(200)
  }
})

ref 1(过时的 wrt 的旧版本googleapis

ref 2(客户端,其中使用 data-requestvisibleactions 更明显)

4

1 回答 1

1

正如您所推测的,您需要将request_visible_actions参数作为调用 oauth 端点的 URL 的一部分。

当前版本的 passport-google-oauth 似乎不支持此参数。从几个未解决的问题和拉取请求来看,作者是否会响应添加它的请求也不清楚。您有两种可能的选择:

  1. 切换到使用 google-api-nodejs-client 中包含的 OAuth 支持

  2. 修补 passport-google-oauth 代码。(并且可能提交一个拉取请求,希望它对其他人有用。)

我不使用 passport.js 或有问题的护照模块,所以我无法对此进行测试,但基于 github 存储库,我认为您可以在lib/passport-google-oauth/oauth2.js之后插入以下内容第 136 行和 return 语句之前:

if (options.requestVisibleActions) {
  // Space separated list of allowed app actions
  // as documented at:
  //  https://developers.google.com/+/web/app-activities/#writing_an_app_activity_using_the_google_apis_client_libraries
  //  https://developers.google.com/+/api/moment-types/
  params['request_visible_actions'] = options.requestVisibleActions;
}
于 2014-07-30T13:13:36.263 回答