Documentation

เวอร์ชัน API 1.1

เอกสารนี้อธิบายวิธีการลงทะเบียน ตั้งค่า และพัฒนาแอปของคุณ เพื่อให้คุณสามารถใช้ API ของเราได้สำเร็จ

สร้างแอป

เพื่อให้แอปของคุณเข้าถึง API ของเราได้ คุณต้องลงทะเบียนแอปของคุณโดยใช้ แดชบอร์ดแอป. การลงทะเบียนจะสร้าง App ID ซึ่งช่วยให้เราทราบว่าคุณคือใคร และช่วยแยกแอปของคุณจากแอปอื่น.

  1. คุณจะต้องสร้างแอปใหม่ สร้างแอปใหม่
  2. เมื่อคุณสร้างแอปแล้ว คุณจะได้รับ app_id และ app_secret
เข้าสู่ระบบด้วย

ระบบเข้าสู่ระบบ (Log in With) เป็นวิธีที่รวดเร็วและสะดวกสำหรับผู้ใช้ในการสร้างบัญชีและเข้าสู่แอปของคุณ ระบบ Log in With ของเราสนับสนุนสองสถานการณ์ คือ การพิสูจน์ตัวตนและการขอสิทธิ์เข้าถึงข้อมูลผู้ใช้ คุณสามารถใช้ระบบเข้าสู่ระบบนี้เพียงเพื่อการพิสูจน์ตัวตน หรือทั้งการพิสูจน์ตัวตนและการเข้าถึงข้อมูล.

  1. ในการเริ่มกระบวนการเข้าสู่ระบบ OAuth คุณต้องใช้ลิงก์สำหรับแอปของคุณดังนี้:
    <a href="https://www.doglala.com/api/oauth?app_id=YOUR_APP_ID">Log in With DOGLALA</a>

    ผู้ใช้จะถูกเปลี่ยนเส้นทางไปยังหน้าการเข้าสู่ระบบดังภาพนี้

  2. เมื่อผู้ใช้ยอมรับแอปของคุณ ผู้ใช้จะถูกเปลี่ยนเส้นทางกลับไปยัง URL เปลี่ยนเส้นทางของแอปของคุณพร้อมกับ auth_key ดังนี้:
    https://mydomain.com/my_redirect_url.php?auth_key=AUTH_KEY
    นี้ auth_key valid only for one time usage, so once you used it you will not be able to use it again and generate new code you will need to redirect the user to the log in with link again.
โทเค็นเข้าถึง

เมื่อคุณได้รับการอนุญาตจากผู้ใช้ผ่านหน้าต่างเข้าสู่ระบบของแอปของคุณ และมีการส่งกลับด้วย auth_key ซึ่งหมายความว่าตอนนี้คุณพร้อมที่จะดึงข้อมูลจาก API ของเราแล้ว และในการเริ่มกระบวนการนี้ คุณจะต้องให้สิทธิ์แอปของคุณและรับ access_token และคุณสามารถทำตามขั้นตอนของเราเพื่อเรียนรู้วิธีรับ.

  1. ในการรับ access token ให้ส่ง HTTP GET ไปยัง endpoint ดังต่อไปนี้ ดังตัวอย่าง:
    <?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://www.doglala.com/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 โดยรองรับพารามิเตอร์ดังต่อไปนี้

Endpoint คำอธิบาย
api/get_user_info

รับข้อมูลผู้ใช้

คุณสามารถดึงข้อมูลผู้ใช้ได้ดังนี้

if(!empty($json['access_token'])) {
    $access_token = $json['access_token']; // your access token
    $get = file_get_contents("https://www.doglala.com/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": ""
  }
}