การผสานรวม SDK ของไฟร์เบส
ทำความเข้าใจวิธีเพิ่ม SDK ของไฟร์เบสลงในแอปพลิเคชันและเริ่มต้นใช้งานร่วมกับบริการต่าง ๆ
การผสานรวม SDK ของไฟร์เบส เป็นบทเรียน Firebase Auth & Realtime Database Apps ฟรีบน CoddyKit นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน Firebase Auth & Realtime Database Apps และความก้าวหน้าของคุณจะซิงค์ข้ามเว็บและแอป CoddyKit คอร์ส Firebase Auth & Realtime Database Apps มีบทเรียนทั้งหมด 4 บทเรียน
บางส่วนของบทเรียนนี้ยังไม่ได้รับการแปล และแสดงเป็นภาษาอังกฤษ
Your App's Firebase Toolkit
The Firebase SDK (Software Development Kit) is the toolkit Firebase gives you — the code and tools that let your app talk to Firebase services.
Why Integrate the SDK?
Why the toolkit? Without the Firebase SDK, your app simply cannot reach Firebase. It is the bridge to auth, databases, storage, and the rest.
SDKs for Different Platforms
Each platform gets its own SDK: JavaScript for web, Java/Kotlin for Android, Swift for iOS, and wrapper SDKs for Flutter or React Native.
Web: Adding the SDK via CDN
For the web, the simplest way to add the SDK is script tags loading Firebase from a CDN. Include only the products you actually plan to use.
<!-- The core Firebase JS SDK must be loaded first -->
<script src="https://www.gstatic.com/firebasejs/9.23.0/firebase-app-compat.js"></script>
<!-- Add Firebase products you want to use -->
<script src="https://www.gstatic.com/firebasejs/9.23.0/firebase-auth-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.23.0/firebase-firestore-compat.js"></script>Your Firebase Configuration Object
Your app needs to know which project to reach, and that lives in the firebaseConfig object — API key, project ID, and more — found in Project settings.
const firebaseConfig = {
apiKey: "YOUR_API_KEY",
authDomain: "YOUR_AUTH_DOMAIN",
projectId: "YOUR_PROJECT_ID",
storageBucket: "YOUR_STORAGE_BUCKET",
messagingSenderId: "YOUR_MESSAGING_SENDER_ID",
appId: "YOUR_APP_ID"
};Initializing Firebase in Web
With the SDK loaded and your config ready, initialize Firebase by calling firebase.initializeApp(config) to open the connection.
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Now Firebase is ready to use!
// For example, you could then get the Auth service:
// const auth = firebase.auth();Try It: Full Web Init Example
Here is a complete minimal HTML page that loads the SDK via CDN and initializes it. Swap in your real config values and watch the console.
<!DOCTYPE html>
<html>
<head>
<title>Firebase Web Init</title>
</head>
<body>
<h1>Check the Console!</h1>
<!-- Firebase SDKs - make sure these are correct versions -->
<script src="https://www.gstatic.com/firebasejs/9.23.0/firebase-app-compat.js"></script>
<script src="https://www.gstatic.com/firebasejs/9.23.0/firebase-auth-compat.js"></script>
<script>
// Your web app's Firebase configuration (replace with your actual config)
const firebaseConfig = {
apiKey: "AIzaSyC...", // Your actual API Key
authDomain: "your-project-id.firebaseapp.com",
projectId: "your-project-id",
storageBucket: "your-project-id.appspot.com",
messagingSenderId: "1234567890",
appId: "1:1234567890:web:abcdef123456"
};
// Initialize Firebase
const app = firebase.initializeApp(firebaseConfig);
console.log("Firebase app initialized successfully!");
console.log(app); // You can inspect the initialized app object
// Now you can access Firebase services, e.g.:
// const auth = firebase.auth();
// console.log("Firebase Auth service ready.");
</script>
</body>
</html>Accessing Firebase Services
After initializing, grab the services you need — like getAuth(app) or getFirestore(app) — from the initialized app instance.
import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth"; // For Authentication
import { getFirestore } from "firebase/firestore"; // For Firestore Database
const firebaseConfig = { /* ... your config ... */ };
// Initialize Firebase
const app = initializeApp(firebaseConfig);
// Get a reference to the Auth service
const auth = getAuth(app);
// Get a reference to the Firestore service
const db = getFirestore(app);
// Now 'auth' and 'db' are ready to be used in your app!Why Initialization is Crucial
Initialization is the handshake: your projectId picks the backend, your apiKey identifies the app, and the SDK wires up service access.
Quick Check: SDK Initialization
You've learned about integrating and initializing the Firebase SDK. Let's see if you can identify the correct first step in connecting your web app to Firebase.
Recap: SDK Integration
Recap: the Firebase SDK connects your app, you add it via CDN for web, your firebaseConfig names the project, and initializeApp opens the link.
เรียนรู้ Firebase Auth & Realtime Database Apps ด้วย AI tutor — ฟรี
เขียนและเรียกใช้โค้ดจริงในเบราว์เซอร์ของคุณ รับความช่วยเหลือทันทีจาก AI tutor 24/7 และเรียนรู้ต่อจากที่คุณหยุดบนเว็บหรือในแอป
- คอร์ส
- 11
- บทเรียน
- 44
คำถามที่พบบ่อย
บทเรียน “การผสานรวม SDK ของไฟร์เบส” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “การผสานรวม SDK ของไฟร์เบส” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Firebase Auth & Realtime Database Apps ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Firebase Auth & Realtime Database Apps มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “การผสานรวม SDK ของไฟร์เบส”
ทำความเข้าใจวิธีเพิ่ม SDK ของไฟร์เบสลงในแอปพลิเคชันและเริ่มต้นใช้งานร่วมกับบริการต่าง ๆ คุณปฏิบัติ Firebase Auth & Realtime Database Apps ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Firebase Auth & Realtime Database Apps หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Firebase Auth & Realtime Database Apps บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 3 จากทั้งหมด 4 บทเรียน
บทเรียน “การผสานรวม SDK ของไฟร์เบส” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Firebase Auth & Realtime Database Apps นี้ได้ไหม
ได้ บทเรียน Firebase Auth & Realtime Database Apps ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- บทนำสู่ระบบนิเวศของไฟร์เบส
- การตั้งค่าโครงการแรกของคุณ
- การผสานรวม SDK ของไฟร์เบส
- ทำความเข้าใจราคาและแพ็กเกจของ Firebase