API版本 1.1
本文档解释如何注册、配置和开发您的应用程序,以便您可以成功使用我们的API
创建应用
为了让您的应用程序访问我们的API,您必须使用以下方式注册您的应用程序 应用仪表板. 注册会创建一个应用ID,让我们知道您是谁,帮助我们区分您的应用和其他应用.
- 您需要创建一个新应用 创建新应用
- 创建应用后您将获得您的 app_id 和 app_secret
登录方式
登录系统是人们创建账户并登录您的应用程序的快速便捷方式。我们的登录系统支持两种场景:身份验证和请求访问人们数据的权限。您可以仅将登录系统用于身份验证,或同时用于身份验证和数据访问.
-
开始OAuth登录过程,您需要使用类似这样的应用链接:
<a href="https://bd.dzwmhyk.top/api/oauth?app_id=YOUR_APP_ID">Log in With 辙隙●Between Discs</a>
用户将被重定向到登录页面,如下所示
-
一旦用户接受您的应用,用户将被重定向到您的应用重定向URL,并附带 auth_key 像这样:
https://mydomain.com/my_redirect_url.php?auth_key=AUTH_KEY
这个 auth_key 仅对一次性使用有效,因此一旦您使用了它,您将无法再次使用它,需要生成新代码时您需要再次将用户重定向到登录链接.
访问令牌
一旦您获得用户对您的应用登录窗口的批准并返回 auth_key 这意味着您现在已准备好从我们的API检索数据,要开始此过程,您需要授权您的应用并获取 access_token 您可以按照我们的步骤学习如何获取它.
-
要获取访问令牌,请向以下端点发出HTTP GET请求,如下所示:
<?php $app_id = "YOUR_APP_ID"; // your app id $app_secret = "YOUR_APP_SECRET"; // your app secret $auth_key = $_GET['auth_key']; // the returned auth key from previous step // Prepare the POST data $postData = [ 'app_id' => $app_id, 'app_secret' => $app_secret, 'auth_key' => $auth_key ]; // Initialize cURL $ch = curl_init('https://bd.dzwmhyk.top/api/authorize'); // Set cURL options for POST curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData)); // Execute request $response = curl_exec($ch); // Check for cURL errors if (curl_errno($ch)) { die('cURL error: ' . curl_error($ch)); } curl_close($ch); // Decode the JSON response $json = json_decode($response, true); // Use the access token if available if (!empty($json['access_token'])) { $access_token = $json['access_token']; // your access token } ?>这个 access_token 仅对1小时有效,因此一旦它失效,您需要通过再次将用户重定向到登录链接来生成新的令牌.
API接口
一旦您获得您的 access_token 现在您可以通过HTTP GET请求从我们的系统检索信息,该请求支持以下参数
| 端点 | 描述 |
|---|---|
| api/get_user_info |
获取用户信息 |
您可以像这样检索用户信息
if(!empty($json['access_token'])) {
$access_token = $json['access_token']; // your access token
$get = file_get_contents("https://bd.dzwmhyk.top/api/get_user_info?access_token=$access_token");
}
结果将是:
{
"user_info": {
"user_id": "",
"user_name": "",
"user_email": "",
"user_firstname": "",
"user_lastname": "",
"user_gender": "",
"user_birthdate": "",
"user_picture": "",
"user_cover": "",
"user_registered": "",
"user_verified": "",
"user_relationship": "",
"user_biography": "",
"user_website": ""
}
}