文件

API版本 1.1

本文檔說明如何註冊、配置和開發您的應用程序,以便您可以成功使用我們的 API

創建 APP

為了讓您的 APP 存取我們的 API,您必須使用 APP 後台. 註冊會建立一個應用程式 ID,讓我們知道您是誰,幫助我們將您的 APP 與其他應用程式區分開來.

  1. 您將需要創建一個新的 APP 创建新应用程式
  2. 創建 APP 後,您將獲得 app_idapp_secret
登入方式

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

  1. 開始 OAuth 登入過程,您需要使用 APP 的鏈接,如下所示:
    <a href="https://magicbox.mg/api/oauth?app_id=YOUR_APP_ID">Log in With MGBOX</a>

    用戶將被重新導向至「登入方式」頁面,如下所示

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

一旦您的 APP 獲得用戶批准,「登入方式」視窗並返回 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://magicbox.mg/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 小時內有效,因此一旦無效,您將需要透過再次將使用者重定向到使用連結登入來產生新的.
APIs

一旦你得到你的 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://magicbox.mg/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": ""
  }
}
MGBOX https://magicbox.mg