23andme 中文文档教程

发布于 9年前 浏览 29 项目主页 更新于 3年前

23andme NPM version

23andMe API 的 JavaScript 包装器。

Installation

使用 NPM 安装包:

$ npm install 23andme

Usage

最小示例:

import API from "23andme";

let clientId = "fake_client_id";
let clientSecret = "fake_client_secret";
let redirectUri = "http://localhost:9000/receive_code";
let scope = ["ancestry"];
let api = new API(clientId, clientSecret, redirectUri, scope);

function receiveCode(code) {
  api.auth(code)
  .then(() => api.ancestry())
  .then(ancestry => console.log(ancestry))
  .catch(err => console.error(err));
}

可以看出,该包公开了一个可以实例化的 API 包装类。 此类具有以下方法:

  • constructor(clientId, clientSecret, redirectUri, scope)
  • Creates an instance of the class.
  • auth(code)
  • Authenticates with the 23andMe API by exchanging an authorization code for an authorization token.
  • Returns a Promise of the authorization token.
  • Call this method first before you make any API requests!
  • user()
  • Retrieves data from the API's /user endpoint.
  • Returns a Promise of the endpoint's response data.
  • names()
  • Retrieves data from the API's /names endpoint.
  • Returns a Promise of the endpoint's response data.
  • haplogroups()
  • Retrieves data from the API's /haplogroups endpoint.
  • Returns a Promise of the endpoint's response data.
  • ancestry()
  • Retrieves data from the API's /ancestry endpoint.
  • Returns a Promise of the endpoint's response data.
  • familyMembers()
  • Retrieves data from the API's /family_members endpoint.
  • Returns a Promise of the endpoint's response data.
  • relatives()
  • Retrieves data from the API's /relatives endpoint.
  • Returns a Promise of the endpoint's response data.

以及以下属性:

  • authUri
  • The URI to redirect the user's Web browser to in order for them to login to 23andMe and be granted an authorization code. (When 23andMe sends the authorization code to your server, pass it to the auth() method!)
  • baseUri
  • The base URI of the 23andMe API.
  • token
  • The authorization token granted when auth() was called.

Disclaimer

该包不以任何方式正式隶属于 23andMe。 使用风险自负。

23andme NPM version

JavaScript wrapper for the 23andMe API.

Installation

Install the package with NPM:

$ npm install 23andme

Usage

Minimal example:

import API from "23andme";

let clientId = "fake_client_id";
let clientSecret = "fake_client_secret";
let redirectUri = "http://localhost:9000/receive_code";
let scope = ["ancestry"];
let api = new API(clientId, clientSecret, redirectUri, scope);

function receiveCode(code) {
  api.auth(code)
  .then(() => api.ancestry())
  .then(ancestry => console.log(ancestry))
  .catch(err => console.error(err));
}

As can be seen, the package exposes an API wrapper class that can be instantiated. This class has the following methods:

  • constructor(clientId, clientSecret, redirectUri, scope)
  • Creates an instance of the class.
  • auth(code)
  • Authenticates with the 23andMe API by exchanging an authorization code for an authorization token.
  • Returns a Promise of the authorization token.
  • Call this method first before you make any API requests!
  • user()
  • Retrieves data from the API's /user endpoint.
  • Returns a Promise of the endpoint's response data.
  • names()
  • Retrieves data from the API's /names endpoint.
  • Returns a Promise of the endpoint's response data.
  • haplogroups()
  • Retrieves data from the API's /haplogroups endpoint.
  • Returns a Promise of the endpoint's response data.
  • ancestry()
  • Retrieves data from the API's /ancestry endpoint.
  • Returns a Promise of the endpoint's response data.
  • familyMembers()
  • Retrieves data from the API's /family_members endpoint.
  • Returns a Promise of the endpoint's response data.
  • relatives()
  • Retrieves data from the API's /relatives endpoint.
  • Returns a Promise of the endpoint's response data.

And the following properties:

  • authUri
  • The URI to redirect the user's Web browser to in order for them to login to 23andMe and be granted an authorization code. (When 23andMe sends the authorization code to your server, pass it to the auth() method!)
  • baseUri
  • The base URI of the 23andMe API.
  • token
  • The authorization token granted when auth() was called.

Disclaimer

The package is not officially affiliated with 23andMe in any way. Use at own risk.

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