本文介绍了使用googleapis node.js api插入Google plus时刻(google-api-nodejs-client)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此处的示例:



和everyauth来处理oauth登录:

(with .withAuth()added)



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

  {domain:global,reason:invalid,message:无效值} 



是否有人能够使用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(函数(编码扩频通信,的accessToken,额外,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 =代码&安培; ACCESS_TYPE =离线&安培; approval_prompt =汽车&安培;范围= 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规范相匹配。



范围似乎被正确处理。登录顺序提示我批准

 此应用想要:
- 了解您的基本配置文件信息和列表你圈子里的人。 (编辑列表)
- 通过Google提供您的创意活动,可见:...

我的代码:

  var moment = {
type:http://schemas.google。 com / CreateActivity,
target:{
id:target-id-2,
type:http://schema.org/CreativeWork,
name:测试时刻,
description:这是一个示例时刻,
text:samplpe g +发布!
}
}


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

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

解决方案

我碰到类似的问题与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'},
有效载荷
).execute(function(result){
console.log(result);
});

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


Using the example here: https://developers.google.com/+/api/latest/moments/insert

and everyauth to handle the oauth login:

(with the .withAuth() added)

Or using my own simpler example I'm getting an "Invalid Value" status code: 400 error.

{"domain":"global","reason":"invalid","message":"Invalid Value"}

Has anyone been able to post a Google + moment using the google-api-nodejs-client library?

I use everyauth to handle oauth and login. My initialization code is below:

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('/');

The code above produces the following 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

Note: I am using the "request-visible-actions" parameter in the url. Also note that the moment type matches the type specified in the code below as well as the schema.org specification for that type of moment.

The scopes seem to be processed correctly. The login sequence prompts me to approve

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:...

My code:

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

I have not had any problems interacting with Google+ or making authorized requests to Google services otherwise but can't seem to get the Google+ moments to insert. Has anyone been able to insert a Google+ moment using the google-api-nodejs-client library?If so, please tell me what I'm doing wrong.

解决方案

i've ran into a similar problem with the youtube api and it seems that way we should call the api from the node library is not the same as specified on the api docs.

specifically instead of doing this:

gapi.client.plus.moments.insert(
  {  'userId' : 'me',
     'collection' : 'vault',
     'resource' : payload
  }
).execute(function(result){
  console.log(result);
});

you have to make the following call:

gapi.client.plus.moments.insert(
  {  'userId' : 'me', 'collection' : 'vault'},
  payload
).execute(function(result){
  console.log(result);
});

the parameters of the requests are passed in the first parameter, and the request body is passed in the second parameter of the function.

这篇关于使用googleapis node.js api插入Google plus时刻(google-api-nodejs-client)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 12:01