1mbsite-node 中文文档教程

发布于 6年前 浏览 19 项目主页 更新于 3年前

1mbsite NodeJS Version Weekly Downloads Licence

1mbsite NodeJS 是一个 NPM 包,用于与 1mbsite API 通信。

注意:这个包中没有函数是同步的,它们都有回调参数,当请求包返回数据时运行 在

Getting Started

开始之前,您必须通过执行以下命令安装 NPM 包:

npm install 1mbsite-node --save

使用此 API 时,您需要提供您的1mbsite account key,您可以通过在这里登录并点击设置中的API类别来获取您的账户密钥。 在那里你应该看到你的帐户密钥。

完成此操作后,您可以通过执行以下操作来请求 1mbsite-node:

const mbsite = require("1mbsite-node");

在请求 1mbsite-node 库之后,您需要通过执行以下操作来创建一个新的 API 实例:

const API = mbsite.API;

现在您可以使用 API 了。

Examples

Verifying your API key

注意:此过程不是必需的,因为此方法是在 API 类的构造函数中调用的。

API.verifyKey(function(result){
// Code here will be executed when the request has returned data
});

verifyKey() 方法需要一个回调参数。 JSON 对象通过回调传递并具有“错误”键和“数据键”。 此处的数据键未使用,但错误键在成功时为真,或在失败时为错误字符串。

Deploying to your 1mb.site

API.deploy("resource", "code", function(result){
// Code here will be executed when the request has returned data
});

deploy() 方法需要一个用于要部署到的资源的字符串参数、另一个用于要部署的代码的字符串参数和一个回调参数。 回调参数通过一个 JSON 对象传递,该对象具有键“error”和“data”。 再一次,数据键未被使用,但错误键要么在成功时返回 true,要么在失败时返回错误字符串。

Viewing a 1mb.site resource

API.viewSite("site name", "resource", function(result){
// Code here will be executed when the request has returned data
});

viewSite() 方法需要一个字符串参数作为站点名称(用户名),另一个字符串参数作为您要查看的资源和一个回调参数。 回调参数通过键为“error”和“data”的 JSON 对象传递。 如果没有错误,则错误键将为假,数据键将为所提供资源的代码字符串。 如果有错误,错误将是字符串错误,数据键将为假。

Listing a sites resources

API.listResources("site name", function(result){
// Code here will be executed when the request has returned data
});

listResources() 方法需要站点名称(用户名)的字符串参数和回调参数。 回调参数通过键为“error”和“data”的 JSON 对象传递。 如果有错误,错误键将是一个错误字符串,但如果没有错误,错误将为假,数据键将是一个包含站点上所有资源的数组。

API 使用 :heart: 由 TwistedAsylumMC 制作!

1mbsite NodeJS Version Weekly Downloads Licence

1mbsite NodeJS is an NPM package built to communicate with the 1mbsite API.

Note: No functions in this package are synchronous, they all have callback parameters which are run when the request package returns data

Getting Started

Before you begin, you must install the NPM package by executing the following command:

npm install 1mbsite-node --save

When using this API you will need to provide your 1mbsite account key, you can obtain your account key by logging in here and clicking the API category in the settings. There you should see your account key.

Once you have this done, you can require 1mbsite-node by doing the following:

const mbsite = require("1mbsite-node");

After requiring the 1mbsite-node library you need to create a new API instance by doing the following:

const API = mbsite.API;

Now you are ready to use the API.

Examples

Verifying your API key

Note: This process is not required as this method is called in the constructor of the API class.

API.verifyKey(function(result){
// Code here will be executed when the request has returned data
});

The verifyKey() method requires a callback parameter. A JSON object is passed through the callback and has an "error" key and a "data key". The data key here is unused but the error key will be true on success, or an error string on failure.

Deploying to your 1mb.site

API.deploy("resource", "code", function(result){
// Code here will be executed when the request has returned data
});

The deploy() method requires a string parameter for the resource you want to deploy to, another string parameter for the code you want to deploy and a callback parameter. The callback parameter passes through a JSON object which has the keys "error" and "data". Once again, the data key is unused but the error key either returns true on success, or an error string on failure.

Viewing a 1mb.site resource

API.viewSite("site name", "resource", function(result){
// Code here will be executed when the request has returned data
});

The viewSite() method requires a string parameter for the site name (a username), another string parameter for the resource you want to view and a callback parameter. The callback parameter passes through a JSON object with the keys "error" and "data". If there are no errors, the error key will be false and the data key will be a string of the code of the provided resource. If there is an error, the error will be a string error and the data key will be false.

Listing a sites resources

API.listResources("site name", function(result){
// Code here will be executed when the request has returned data
});

The listResources() method requires a string parameter for the site name (a username) and a callback parameter. The callback parameter passes through a JSON object with the keys "error" and "data". If there is an error, the error key will be an error string, but if there is no error, error will be false and the data key will be an array with all the resources on a site.

API made with :heart: by TwistedAsylumMC!

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文