ตัวอย่างโค้ด

ตัวอย่างการใช้งาน Phaya API ในภาษาต่างๆ

example.js
// อัพโหลดไฟล์วิดีโอ
const uploadVideo = async (file) => {
  const formData = new FormData();
  formData.append('file', file);

  const response = await fetch('https://api.phaya.io/api/v1/media/upload', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer phaya_live_xxxxxxxxxxxx'
    },
    body: formData
  });

  if (!response.ok) {
    throw new Error(`Upload failed: ${response.statusText}`);
  }

  const data = await response.json();
  console.log('Uploaded:', data);
  return data;
};

// ใช้งาน
const fileInput = document.getElementById('videoFile');
uploadVideo(fileInput.files[0])
  .then(result => console.log('Success:', result))
  .catch(error => console.error('Error:', error));

💡 เคล็ดลับ

  • • เก็บ API key ของคุณไว้อย่างปลอดภัย
  • • ใช้ test key สำหรับ development
  • • ตรวจสอบสถานะงานเป็นระยะ
  • • จัดการ error ให้เหมาะสม

🚀 Best Practices

  • • ใช้ environment variables สำหรับ API keys
  • • ตั้ง timeout ที่เหมาะสม
  • • Retry เมื่อเกิด temporary errors
  • • Log ข้อมูลสำคัญสำหรับ debugging

ต้องการความช่วยเหลือ?

ดูเอกสารฉบับเต็มหรือติดต่อทีมสนับสนุนของเรา