23andme 中文文档教程
23andme
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
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.
更多
你可能也喜欢
- 3h-jdh5-cli 中文文档教程
- 4electron 中文文档教程
- @0x/coordinator-server 中文文档教程
- @0xcert/ethereum-xcert 中文文档教程
- @128technology/mui-virtualized-table 中文文档教程
- @12stonechurch/react-native-video-controls 中文文档教程
- @14islands/lerp 中文文档教程
- @19labs/generator-gale-wellness 中文文档教程
- @25sprout/react-starter 中文文档教程
- @2now/gatsby-theme-minimal-blog-core 中文文档教程