问题标签 [json-api]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
527 浏览

json - Wordpress JSON API - 从内容中删除字符

我正在使用 Wordpress JSON API 插件将我的帖子获取为 json。我将这些数据用于我的 AngularJS 项目。如何从我通过 JSON api 获得的帖子内容部分中删除字符和 p 标签。

所以我可以在我的页面上显示:

0 投票
2 回答
209 浏览

json - How To Tell When A JSON Request Is Received In Wordpress?

I am using a JSON API plugin for wordpress to allow me to work with the sites content in a phonegap application I'm building.

However due to the complexity of some of the content on the site (caused by shortcodes outputting graphs, sliders etc..) these aren't suitable to be displayed in the mobile app. I need to remove the shortcodes from the JSON output.

I have found that I can hook into the_content filter in wordpress and use remove_shortcode to take out the necessary shortcodes. But the problem is I can only do this when I access the json url via my browser.

For example, I may use http://example.com?json=1 to return recent posts. If I type this in my url bar I can parse the url, determine that json=1 is there and strip the shortcodes.

However when I am doing an ajax (JSONP) request from my mobile application, it doesn't appear to be able to check the url for the json parameter, thus my shortcodes are not being stripped. I can't even pass in any headers either as they won't make it because of the nature of JSONP requests I believe.

Has anyone got any ideas as to how I can figure out when a JSON request from my mobile application is received, so that I can then remove the shortcodes?

Something like

And before it's brought up, I have asked this on the Wordpress Stackexchange but to no avail

Update: Here is the code I use for the ajax request from the mobile app

0 投票
1 回答
449 浏览

jquery - 将 filter.js 流与 Wordpress JSON API 一起使用

我有filter.jsWordpress JSON API配合得很好,但我不得不告诉 JSON API 输出所有帖子但指定&count=-1(通常它们在 10 秒内分页)。

这很好,虽然没有大量的帖子,但随着添加的帖子越多,Wordpress JSON API生成 JSON 所需的时间就越长。

filter.js提供流式传输,它可以抓取 JSON 文件的块并将它们增量添加到页面中。

真正的问题:

如何获得“流式传输”(具有 AJAX 请求格式.json?offset=0&limit=50)以使用 Wordpress JSON API 分页结果?每个新页面都需要一个新的Wordpress JSON API调用&page=2等。

以下是我到目前为止的相关代码,但您可以在此处的粘贴箱中找到所有代码:http: //pastebin.com/EKhBddmh

0 投票
1 回答
80 浏览

ember.js - 如何为 ember.js 隔离sails.js 中每个用户群的所有数据?

我想构建一个简单的 ember 应用程序,以sails 作为后端。有很好的蓝图可以帮助我解决这个问题,但我希望所有数据都完全与用户隔离。所以它实际上是一个单用户应用程序,但适用于多个用户。

因此,每个用户的所有数据都是不同的。所以当 ember 向我发出请求时,/notes/findAll我只想返回与用户对应的注释。另一方面,用户对属于他的所有数据拥有完全权限(可能除了用户模型,这是唯一的特殊情况)。

最简单的方法是什么?

  • 我可以自己修改蓝图!但这是个好主意吗?如果以后能够通过基于每个模型的配置来组合它,那就太好了。

  • 有没有办法通过政策做到这一点?那么设置安全用户过滤器的策略?

  • 还有另一种更好/默认的方法来解决我的问题吗?

谢谢!

0 投票
2 回答
6408 浏览

node.js - 我的 Web Apps API 是否需要 Oauth2

我正试图围绕构建基于 express.js / node.js 的 REST API 进行思考。我有一些问题...

  1. 如果我现在只关心 Web 应用程序(不一定是电话应用程序),我的 api 是否需要基于令牌/oauth 1 或 2 的安全性

  2. 是否有任何资源可以学习如何从头开始构建它?我已经阅读了谷歌搜索“rest api with oauth2 authentication express.js”的前 3 页,但我仍然没有掌握它。

0 投票
0 回答
295 浏览

php - Twitter Rest API,试图解析数据

我正在尝试获取用户提要的所有图像。我正在创建的文件是一个 CRON 作业,但会检查数据库中是否有任何已提交的用户名,然后转到 Twitter API 并获取用户的提要,然后特别是图像。我遇到的问题是我似乎无法浏览响应。目前我正在使用 json_decode(TWITTERS RESPONSE HERE) 在此之后我无法进入“较低级别”的数据。我的代码如下:

在 $data 上执行“var dump”时(我将 api 调用更改为“count=1”以节省它包含的空间:

以下是实际 API 调用返回的内容(有 20 个结果):

]

0 投票
1 回答
72 浏览

rest - 如何以 REST 方式在资源上定义转换?

我正在设计一个 REST api,遵循最佳实践,包括一种超媒体/仇恨形式。我正在使用jsonapi作为设计指南,这似乎很完整。

目前,我需要:

  1. 在响应中组合 2 个资源(一个资源 A 和一个相关的资源 B)。我使用jsonapi 中指定的复合文档结构来执行此操作。或者也俗称资源扩张
  2. 以专门的方式格式化 1. 的结果,以便期望所述格式化的专门客户可以轻松地使用它。

我的问题是2。我如何以 REST 方式正确表示这一点?看来我可能需要一个单独的端点,但这不是“RESTy”,因为这意味着一个单独的资源,而它只是同一资源输出的转换。

有关如何执行此操作的任何参考?

0 投票
2 回答
76 浏览

mongodb - 确保用户仅在 REST API 中访问他们的记录

我目前正在为我的下一个 Web 应用程序在 node.js 和 express.js 上构建一个 rest api。我正在构建一个多租户 SAAS 应用程序,我只是想知道根据 REST API 标准(如果还存在这样的东西)的最佳或“最可接受”的方式,以便如果用户调用 api说:

/api/用户

这不是拉数据库(mongodb)中的每个用户,而是拉特定用户公司成员。

我可以调用:api/users/?companyId=1,但我不禁认为必须有更好的方法。也许将公司 ID 与每个 api 调用一起作为某种标题传递?

对此的任何想法将不胜感激。

0 投票
1 回答
532 浏览

ruby-on-rails - 功能测试:Rails 4 中 JSON API 的更新操作

我已经为此苦苦挣扎了很长时间,尝试了谁知道有多少组合-无济于事。似乎 SO 和 Google 上的其他几个人无法解决这个问题。

本质上,我在 Rails 4 的内置功能测试框架内的控制器上发布 :update 操作。我的应用程序严格来说是一个 JSON API,所以我需要将 :update 请求作为 JSON 请求发布。在野外一切都很好,但功能测试语法似乎无法掌握我需要的东西。

这是我目前的尝试:

运行 rake test 会导致语法错误:

为清楚起见,我的控制器操作如下所示:

我在这里想念什么?甚至可以使用 Rails 4 的内置功能测试框架测试 JSON 帖子吗?官方文档在这个问题上非常简洁。

0 投票
1 回答
768 浏览

json - AngularJS 和 JsonStub

我们目前正在尝试使用AngularJS从JsonStub获取 Json 数据。我们尝试复制 JsonStub 的示例,但没有成功将其与我们的 apikey 一起使用。

我们只想{"message":"hello world!"}在 JsonStub 的 AngularJS 中显示。

这是我们的代码,请让我知道我们做错了。

谢谢你。

控制器

JsonStub 在此处输入图像描述