Google+使用Node.js客户端插入时刻 [英] Google+ insert moment with nodejs client

查看:95
本文介绍了Google+使用Node.js客户端插入时刻的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能获得google-api-nodejs-client来成功插入时刻吗?

Has anyone been able to get the google-api-nodejs-client to successfully insert a moment?

无论我尝试什么,我都会收到一般性的400无效值"错误,但是由于

Whatever I try, I get a generic 400 "Invalid value" error but am unable to narrow down the invalid value because the API Explorer doesn't work either.

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

Would it be because of the missing data-requestvisibleactions parameter? I'm using passport.js's require('passport-google-oauth').OAuth2Strategy for handling oauth access, and that part is working fine, but I have no idea how to incorporate requestvisibleactions into the oauth request flow since this is definitely not originating from a clientside form.

这是我要执行的操作的摘要(使用最新版本的googleapis,v1.0.2):

Here's a snippet of what I'm trying to do (using the latest version of 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)
  }
})

参考1 (旧版本的googleapis已过期)

参考2 (客户端,其中data-requestvisibleactions的使用是更明显)

ref 2 (client-side, where the use of data-requestvisibleactions is more obvious)

推荐答案

您推测,您需要request_visible_actions参数作为调用oauth端点的URL的一部分.

As you speculated, you need the request_visible_actions parameter as part of the URL calling the oauth endpoint.

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

It looks like the current version of passport-google-oauth doesn't support this parameter. Judging by several of the open issues and pull requests, it isn't clear that the author will respond to requests to add it either. You have two possible options:

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

  1. Switch to using the OAuth support that is included in google-api-nodejs-client

修补护照-google-oauth代码. (并可能提交拉取请求,希望对其他人有用.)

Patch the passport-google-oauth code. (And possibly submit a pull request in the hopes it will be useful to someone else.)

我不使用passport.js或有问题的passport模块,因此无法对此进行测试,但是基于github存储库,我认为您可以在

I don't use passport.js or the passport module in question, so I can't test this, but based on the github repository, I think you can insert the following in lib/passport-google-oauth/oauth2.js after line 136 and before the return statement:

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;
}

这篇关于Google+使用Node.js客户端插入时刻的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆