首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用googleapis客户端接口( google - api -nodejs- node.js )插入google+ moment

使用googleapis客户端接口( google - api -nodejs- node.js )插入google+ moment
EN

Stack Overflow用户
提问于 2013-12-10 19:13:55
回答 2查看 1.4K关注 0票数 0

使用这里的示例:https://developers.google.com/+/api/latest/moments/insert

以及处理oauth登录的所有身份验证:

(添加了.withAuth() )

或者使用我自己的更简单的例子,我得到了一个“无效的值”状态代码: 400错误。

代码语言:javascript
复制
{"domain":"global","reason":"invalid","message":"Invalid Value"}

有没有人能够使用google-api-nodejs-client库发布Google +时刻?

我使用每个身份验证来处理oauth和登录。我的初始化代码如下:

代码语言:javascript
复制
everyauth.google
  .appId(conf.googlehybrid.clientId)
  .appSecret(conf.googlehybrid.clientSecret)
  .scope('https://www.googleapis.com/auth/plus.login\
          https://www.googleapis.com/auth/plus.moments.write')
  .findOrCreateUser( function (sess, accessToken, extra, googleUser) {
    googleUser.refreshToken = extra.refresh_token;
    googleUser.expiresIn = extra.expires_in;
    return usersByGoogleId[googleUser.id] || (usersByGoogleId[googleUser.id] = addUser('google', googleUser));
  })
  .redirectPath('/');

上面的代码生成了以下url:

https://accounts.google.com/o/oauth2/auth?client_id=507792786278.apps.googleusercontent.com&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fauth%2Fgoogle%2Fcallback&response_type=code&access_type=offline&approval_prompt=auto&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.moments.write&request_visible_actions=http:%2F%2Fschemas.google.com%2FCreateActivity

注意:我在url中使用了"request-visible-actions“参数。另请注意,力矩类型与以下代码中指定的类型以及该力矩类型的schema.org规范相匹配。

作用域似乎被正确处理。登录顺序提示我批准

代码语言:javascript
复制
This app would like to:
   -Know your basic profile info and list of people in your circles. (Edit list)    
   -Make your creative activity available via Google, visible to:...

我的代码:

代码语言:javascript
复制
var moment = {
  "type":"http://schemas.google.com/CreateActivity",
  "target": {
    "id": "target-id-2",
    "type": "http://schema.org/CreativeWork",
    "name": "Test moment",
    "description": "This is a sample moment",
    "text": "samplpe g+ posting!"
  }
}


gapi.client.plus.moments.insert(
  {  
     'userId': 'me',
     'collection': 'vault',
     'resource': moment
  })
 .withAuthClient(authObject)
 .execute(callback);
}

我在与Google+交互或向谷歌服务发出授权请求时没有遇到任何问题,但似乎无法插入Google+ moments。有没有人能够使用google-api-nodejs-client库插入一个Google+时刻?如果是这样,请告诉我我做错了什么。

EN

回答 2

Stack Overflow用户

发布于 2013-12-31 06:42:43

我在youtube api中遇到了类似的问题,似乎我们应该从节点库调用api的方式与api文档中指定的方式不同。

具体来说,不是这样做:

代码语言:javascript
复制
gapi.client.plus.moments.insert(
  {  'userId' : 'me',
     'collection' : 'vault',
     'resource' : payload
  }
).execute(function(result){
  console.log(result);
});

您必须进行以下调用:

代码语言:javascript
复制
gapi.client.plus.moments.insert(
  {  'userId' : 'me', 'collection' : 'vault'},
  payload
).execute(function(result){
  console.log(result);
});

请求的参数在第一个参数中传递,请求主体在函数的第二个参数中传递。

票数 1
EN

Stack Overflow用户

发布于 2013-12-12 03:51:32

我已经能够使用相同的时刻对象和Python在Python中使用谷歌的OAuth应用程序接口来运行这个示例。

似乎在google-api-nodejs-client打包我的请求以插入片刻的方式中存在一些错误。

我没有时间进一步研究,所以我将继续使用Python。

我仍然更喜欢使用Node。如果任何人拿出一个bug修复或解决方案来使其在Node api中工作,请让我知道。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20492925

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档