Google+与nodejs客户端插入时刻

时间:2014-07-29 18:32:57

标签: node.js oauth-2.0 google-plus google-api-nodejs-client

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

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

是否因为缺少data-requestvisibleactions参数?我正在使用passport.js的require('passport-google-oauth').OAuth2Strategy来处理oauth访问,并且该部分工作正常,但我不知道如何将请求可执行动作合并到oauth请求流中,因为这绝对不是源于客户端表单。 / p>

以下是我正在尝试做的一小部分(使用最新版本的googleapis,v1.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(过时的w.r.t. googleapis的旧版本)

ref 2(客户端,数据请求可见性的使用更明显)

1 个答案:

答案 0 :(得分:1)

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

看起来当前版本的passport-google-oauth不支持此参数。从几个未解决的问题和拉取请求来判断,作者将回应添加请求的请求并不清楚。您有两种可能的选择:

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

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

  3. 我没有使用passport.js或相关的护照模块,因此我无法对此进行测试,但基于github存储库,我认为您可以在lib/passport-google-oauth/oauth2.js中插入以下内容在第136行之后和返回声明之前:

    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;
    }
    
相关问题