การสร้างคีย์สำหรับใช้งาน Youtube API V3
ก่อนอื่น คุณต้องมีบัญชี Google ก่อน และทำการ Login จากนั้นให้ไปที่ https://console.developers.google.com/project ในกรณีที่คุณเข้ามาครั้งแรกให้คุณสร้างโปรเจ็คก่อน โดยคลิกที่ Create Project

ที่กรอบ New Project กรอกชื่อโปรเจ็คที่ต้องการ ตามตัวอย่างนี้ผมสร้างโปรเจ็คชื่อ Kotchasan และกด Create

หลังจากนั้นที่กรอบ Overview ใหมองหาตัวเลือก Youtube Data API ภายใต้ส่วน Youtube APIs แล้วคลิกเข้าไป (เนื่องจากเราต้องการสร้างคีย์าหรับใช้งาน Youtube เลยต้องเลือกตัวเลือกนี้)

ที่กรอบถัดมาเราต้องเปิดใช้งาน Youtube Data API ก่อน โดยคลิกปุ่ม Enabled

ปุ่มจะเปลี่ยนเป็น Disabled จากนั้นคลิกต่อที่ Credentials

ที่หน้า Credentials ให้กดตามลำดับ 1 ถึง 4 เลยครับ

ในกรอบ Create browser API key กรอกชื่อ key (ช่อง Name) ที่ต้องการ และหากต้องการให้ key สามารถใช้งานได้บนไซต์ที่เรากำหนดให้กรอก URL ของไซต์ลงในช่อง Accept requests from these HTTP referrers ด้วยก็ได้ (ไม่จำเป็น) เสร็จแล้วกด Create

ในกรอบถัดมาเราจะได้ API key ออกมาแล้วกด OK ต่อไปเลยครับ

หน้าสุดท้ายจะเป็นสรุปภาพรวมของคีย์อีกครั้ง ถึงตอนนี้คีย์ของเราพร้อมใช้งานแล้วครับ

หากต้องการทดสอบว่าสามารถใช้งานได้หรือไม่ ให้แทนที่ API key ด้วยคีย์ที่ได้มา และ video IDs ด้วย ID ของ Video ที่ต้องการเลยครับ









https://www.googleapis.com/youtube/v3/videos?part=snippet&id={video IDs}&key={API key}
ทิป
- การสร้างหรือแก้ไขคีย์แต่ละครั้ง อาจต้องใช้เวลาถึง 5 นาทีเพื่อให้การเปลี่ยนแปลงมีผล
- หากไซต์ที่ใช้งานคีย์ยังไม่ได้ยืนยันการเป็นเจ้าของเว็บไซต์กับ Webmaster Tools อาจไม่สามารถใช้งานคีย์ได้ ให้ดำเนินการยืนยันไซต์ก่อน