使用这里的示例:https://developers.google.com/+/api/latest/moments/insert
以及处理oauth登录的所有身份验证:
(添加了.withAuth() )
或者使用我自己的更简单的例子,我得到了一个“无效的值”状态代码: 400错误。
{"domain":"global","reason":"invalid","message":"Invalid Value"}有没有人能够使用google-api-nodejs-client库发布Google +时刻?
我使用每个身份验证来处理oauth和登录。我的初始化代码如下:
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:
注意:我在url中使用了"request-visible-actions“参数。另请注意,力矩类型与以下代码中指定的类型以及该力矩类型的schema.org规范相匹配。
作用域似乎被正确处理。登录顺序提示我批准
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:...我的代码:
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+时刻?如果是这样,请告诉我我做错了什么。
发布于 2013-12-31 06:42:43
我在youtube api中遇到了类似的问题,似乎我们应该从节点库调用api的方式与api文档中指定的方式不同。
具体来说,不是这样做:
gapi.client.plus.moments.insert(
{ 'userId' : 'me',
'collection' : 'vault',
'resource' : payload
}
).execute(function(result){
console.log(result);
});您必须进行以下调用:
gapi.client.plus.moments.insert(
{ 'userId' : 'me', 'collection' : 'vault'},
payload
).execute(function(result){
console.log(result);
});请求的参数在第一个参数中传递,请求主体在函数的第二个参数中传递。
发布于 2013-12-12 03:51:32
我已经能够使用相同的时刻对象和Python在Python中使用谷歌的OAuth应用程序接口来运行这个示例。
似乎在google-api-nodejs-client打包我的请求以插入片刻的方式中存在一些错误。
我没有时间进一步研究,所以我将继续使用Python。
我仍然更喜欢使用Node。如果任何人拿出一个bug修复或解决方案来使其在Node api中工作,请让我知道。
https://stackoverflow.com/questions/20492925
复制相似问题