使用此处的示例:https ://developers.google.com/+/api/latest/moments/insert
和everyauth 来处理oauth 登录:
(添加了 .withAuth() )
或者使用我自己更简单的示例,我收到“无效值”状态代码:400 错误。
{"domain":"global","reason":"invalid","message":"Invalid Value"}
有没有人能够使用 google-api-nodejs-client 库发布 Google + 时刻?
我使用everyauth 来处理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 中使用“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 服务发出授权请求时没有遇到任何问题,但似乎无法插入 Google+ 时刻。有没有人能够使用 google-api-nodejs-client 库插入 Google+ 时刻?如果是这样,请告诉我我做错了什么。