文件說明

API版本 1.1

本文件解釋瞭如何註冊、配置和開發您的應用程式,以便您可以成功使用我們的 API

建立應用程式

為了讓您的應用程式訪問我們的 API,您必須使用 應用程式儀錶板. 註冊會建立一個應用程式 ID,讓我們知道您是誰,幫助我們將您的應用程式與其他應用程式區分開來.

  1. 您將需要建立一個新的應用程式 建立新應用程式
  2. 建立應用程式後,您將獲得 app_idapp_secret
登入方式

使用系統登入是人們建立帳戶和登入您的應用程式的一種快速便捷的方式。我們的登入系統支援兩種場景:身分驗證和請求訪問人員資料的許可權。您可以使用登入系統僅進行身分驗證或同時進行身分驗證和資料訪問.

  1. 開始 OAuth 登入過程,您需要使用您的應用程式的連結,如下所示:
    <a href="https://dashidai.live/api/oauth?app_id=YOUR_APP_ID">Log in With 大時代 | 無審查華人時政社群</a>

    使用者將被重定向到“登入方式”頁面,如下所示

  2. 使用者接受您的應用程式後,使用者將被重定向到您的應用程式重定向 URL auth_key 像這樣:
    https://mydomain.com/my_redirect_url.php?auth_key=AUTH_KEY
    這個 auth_key 僅對一次使用有效,因此一旦使用它,您將無法再次使用它並生成新程式碼,您需要將使用者重定向到再次使用連結登入.
訪問令牌

一旦您的應用程式獲得使用者批准,“登入方式”視窗並返回 auth_key 這意味著現在您已準備好從我們的 API 檢索資料並開始此過程,您需要授權您的應用程式並獲取 access_token 您可以按照我們的步驟來了解如何獲取它.

  1. 要獲取訪問令牌,請向以下端點發出 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://dashidai.live/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://dashidai.live/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": ""
          }
        }