Tag: api

更新子文件mongoose中的字段

我的父母模型 var GameChampSchema = new Schema({ name: String, gameId: { type: String, unique: true }, status: Number, countPlayers: {type: Number, default: 0}, companies: [ { name: String, login: String, pass: String, userId: ObjectId } ], createdAt: {type: Date, default: Date.now}, updateAt: Date }) 我需要插入userId属性第一个孩子,他没有设置 所以,只有在条件({status:0,countPlayers:{$ lt:10})

向节点注册Glass时间线通知

我正在尝试注册TAKE_A_NOTE与“镜像API订阅”事件侦听器。 我没有任何运气:我可以启动与“我的应用程序”注意,但是,没有控制台日志,事件已被识别。 我想知道TAKE_A_NOTE函数何时发生或完成,然后处理响应。 我不知道订阅是否应该在stream中,或者如果我以错误的方式实现EventListener。 你的帮助将不胜感激。 我正在使用的代码是: //引用 // http://www.recursiverobot.com/post/57348836217/getting-started-with-the-mirror-api-using-node-js // https://www.npmjs.org/package/mirror-api-subscription var express = require('express') ,http = require('http') ,https = require('https') ,fs = require('fs') ,googleapis = require('googleapis') ,OAuth2Client = googleapis.OAuth2Client; var app = express(); var oauth2Client = new OAuth2Client(process.env.MIRROR_DEMO_CLIENT_ID, process.env.MIRROR_DEMO_CLIENT_SECRET,process.env.MIRROR_DEMO_REDIRECT_URL); //所有环境 app.set('port',8888); app.use(express.logger( 'dev的')); app.use(express.bodyParser()); app.use(express.methodOverride()); app.use(app.router); var gotToken = function(){ googleapis .discover('mirror','v1') .execute(function(err,client){ if(!! […]

Express js控制器从api服务获取数据并呈现视图

我有这个系统 一个只有JSON对象响应的API系统。 例如: http : //example.com/user/13 response:{name:'Aesome 1',age:'13'} ExpressJS Web应用程序创build视图并将视图发送给用户。 现在我需要做的是从API获取JSON对象,并在ExpressJS中渲染视图,然后发送到客户端。 所以我需要连接ExpressJS应用程序与这个API系统。 请让我知道如何做到这一点。 谢谢

隐藏获取请求键

我正在使用新的OMDB api,并希望在客户端保持提取请求(包括密钥)不可见。 下面是用户打开开发工具时的问题示例: 。 我在React中完成所有的调用,如下所示: import OmdbKey from './OmdbKey'; populate(keystrokes) { let query = "http://www.omdbapi.com/?s="; fetch(query + keystrokes + '&apikey=' + OmdbKey ) .then((response) => { response.json().then((json) => { this.setState({ results: json.Search }); }); }); } 有没有办法做到这一点,所以我可以隐藏在GET请求中的密钥? 如果不是,我该怎么办? 谢谢

pipe理node.js中基于命令的TCP套接字API的连接

我构build了一个基于expresss.js的RESTful API,通过使用JSON的TCP套接字与远程服务器进行通信。 请求的URL被转换成适当的JSON消息,新的TCP套接字打开并且发送消息。 然后,当接收到来自同一连接的消息时,事件被触发,JSON回复将被计算,并且由于GET请求返回新的JSON消息。 可能的path: asynchronous(当前正在使用) – 为每个请求打开到服务器的连接。 同步 – 创build一个包含所有请求的队列,并等待响应,阻止代码。 跟踪 – 一次发送所有请求,并asynchronous收到答案。 在请求上使用跟踪者ID来将每个请求与其答案关联起来。 什么是最好的方向去? 有没有什么共同的模式来解决这种应用?

通过节点客户端调用Google API时出现“套接字挂起”错误

以下代码在此处使用Google的nodejs客户端版本0.7调用Google Analytics报告API。 它在一些执行中返回socket hang up错误,但并不总是如此。 这是否会成为Google服务器端的错误? 有没有简单的方法来debugging? 顺便说一句,我连续打几个电话,不知道是否是由速率限制造成的。 gapi = require "googleapis" authClient = new gapi.auth.JWT( config.ga.clientEmail, config.ga.privateKeyPath, null, [config.ga.scopeUri] ) authPromise = new Promise (resolve, reject) -> authClient.authorize (err, token) -> resolve token return return authPromise.then -> gapi.discover('analytics', 'v3') .withAuthClient(authClient) .execute (err, client) -> …

如何使用nodejs和express在REST API中实现search和过滤

我正在通过构buildREST API来学习和使用Node和Express。 我没有任何数据库来存储数据,我做了一切在内存中。 比方说,我有一个用户数组: var users = [{"id": "1", "firstName": "John", "lastName": "Doe"}]; 并定义了一个getAllUser函数: exports.getAllUser = function(page, items) { page = (page < 1 ? 1 : page) || 1; items = (items < 1 ? 5 : items) || 5; var indexStart, indexEnd; indexStart = (page – 1) * items; indexEnd = indexStart + […]

环回如何设置嵌套关系

我最近在玩Strongloop Loopback (即: http : //loopback.io/ ),这是一个很棒的工具。 我经历了他们的示例,它的工作原理非常好。 但这是基本的例子; 基于下面的简单数据模型(可以开始): 原始样本 现在,如果你考虑一个稍微复杂一点的数据模型…让我们来说一个关于漫画( http://developer.marvel.com/docs )的数据模型,在这个模型中你有几个由几部漫画组成的系列,漫画中你有很多字符。 更新:在系列和漫画之间添加了一个子系列模型 如果我在回送关系中翻译这个: Serie hasMany Sub-series Sub-series belongsTo a Serie Sub-serie hasMany Comics Comic belongsTo a Sub-serie Comic hasMany Characters Character belongsTo a Comic 这是我的问题, 如何获得给定系列的所有字符? 我应该如何描述这种关系 。

Highrise API正在返回一个404错误

我正在使用Highrise存储客户信息的Web应用程序,该应用程序使用node.js,我正在使用npm包打高层的API。 当我尝试点击api添加一个客户时,它正在发送一个请求到正确的path(/people.xml)根据highrise文档,但它总是返回一个404错误,这可能是什么问题呢?

Reddit API只返回一个post

我正在尝试使用API​​获取所有在subreddit中的链接,但它只返回一个url。 这里是我有的代码: var request = require('request'); webpage = 'http://www.reddit.com/r/AmazonUnder5/top.json?limit=100'; //login request.post('http://www.reddit.com/api/login',{form:{api_type:'json', passwd:'password', rem:true, user:'username'}}); //get urls request({uri : webpage, json:true, headers:{useragent: 'mybot v. 0.0.1'}}, function(error, response, body) { if(!error && response.statusCode == 200) { for(var key in body.data.children) { var url = body.data.children[key].data.url; console.log(url); } } }); 当我在浏览器中访问json链接时,它将返回全部100个post。