สรุปสาระสำคัญ
Instagram Graph API ช่วยให้นักพัฒนาสามารถจัดการบัญชี Instagram Business และ Creator ได้ด้วยโปรแกรม โดยใช้การยืนยันตัวตน Facebook Login OAuth 2.0, ปลายทาง (endpoints) ที่ใช้ GraphQL สำหรับการเผยแพร่เนื้อหา, ข้อมูลเชิงลึก, ความคิดเห็น, และการส่งข้อความ พร้อมข้อจำกัดในการเรียกใช้ 200 ครั้งต่อชั่วโมงต่อแอป คู่มือนี้ครอบคลุมการตั้งค่าการยืนยันตัวตน, การเผยแพร่เนื้อหา, การเรียกดูข้อมูลเชิงลึก, การจัดการความคิดเห็น, และกลยุทธ์การผสานรวมในสภาพแวดล้อมจริง
บทนำ
Instagram มีผู้ใช้งานมากกว่า 2 พันล้านคนต่อเดือน และมีธุรกิจกว่า 200 ล้านรายที่ใช้บัญชี Instagram Business สำหรับนักพัฒนาที่สร้างเครื่องมือจัดการโซเชียลมีเดีย, แพลตฟอร์มวิเคราะห์, หรือการผสานรวมอีคอมเมิร์ซ การผสานรวม Instagram Graph API เป็นสิ่งจำเป็นสำหรับการเข้าถึงกลุ่มเป้าหมายขนาดใหญ่นี้
นี่คือความจริง: ผู้จัดการโซเชียลมีเดียที่ดูแลบัญชีมากกว่า 10 บัญชี ต้องเสียเวลา 20-30 ชั่วโมงต่อสัปดาห์ไปกับการโพสต์ด้วยตนเอง, การตอบกลับความคิดเห็น, และการรวบรวมข้อมูลวิเคราะห์ การผสานรวม Instagram API ที่แข็งแกร่งจะช่วยให้การเผยแพร่เนื้อหา, การกลั่นกรองความคิดเห็น, การวิเคราะห์ความรู้สึก, และการรายงานประสิทธิภาพเป็นไปโดยอัตโนมัติ
คู่มือนี้จะอธิบายขั้นตอนการผสานรวม Instagram Graph API อย่างสมบูรณ์ คุณจะได้เรียนรู้เกี่ยวกับการยืนยันตัวตนด้วย Facebook Login, การเผยแพร่เนื้อหา, ข้อมูลเชิงลึกของสื่อ, การจัดการความคิดเห็น, การผสานรวมเว็บฮุค, และกลยุทธ์การนำไปใช้งานจริง เมื่อสิ้นสุด คุณจะมีการผสานรวม Instagram ที่พร้อมใช้งานในสภาพแวดล้อมจริง
💡Apidog ช่วยลดความซับซ้อนในการทดสอบการผสานรวม API ทดสอบปลายทาง Instagram ของคุณ, ตรวจสอบความถูกต้องของ OAuth flows, ตรวจสอบการตอบสนองของ API, และแก้ไขปัญหาการเผยแพร่ในพื้นที่ทำงานเดียว นำเข้าข้อกำหนด API, ตอบกลับจำลอง, และแบ่งปันสถานการณ์ทดสอบกับทีมของคุณ
Instagram Graph API คืออะไร?
Instagram Graph API ให้การเข้าถึงบัญชี Instagram Business และ Creator แบบโปรแกรมผ่าน Facebook Graph API โดย API จัดการสิ่งเหล่านี้:
- การเผยแพร่เนื้อหา (รูปภาพ, วิดีโอ, Reels, แคโรเซล)
- ข้อมูลเชิงลึกและการวิเคราะห์ของสื่อ
- การจัดการความคิดเห็นและการกล่าวถึง
- การส่งข้อความโดยตรง (ผ่าน Instagram Graph API + Messenger Platform)
- การติดตามแฮชแท็กและการกล่าวถึง
- การจัดการสตอรี่
- การช้อปปิ้งและแท็กสินค้า
คุณสมบัติหลัก
| คุณสมบัติ | คำอธิบาย |
|---|---|
| API แบบ Graph | การเข้าถึงทรัพยากรแบบ Node |
| OAuth 2.0 | การยืนยันตัวตนด้วย Facebook Login |
| Webhooks | การแจ้งเตือนแบบเรียลไทม์สำหรับความคิดเห็น, การกล่าวถึง |
| การจำกัดอัตราการเรียกใช้ | 200 ครั้งต่อชั่วโมงต่อแอป |
| การเผยแพร่เนื้อหา | รูปภาพ, วิดีโอ, Reels, แคโรเซล |
| ข้อมูลเชิงลึก | เมตริกการมีส่วนร่วม, การเข้าถึง, การแสดงผล |
| การกลั่นกรอง | การจัดการความคิดเห็น, การกล่าวถึง, ข้อความ |
ข้อกำหนดของบัญชี
| ประเภทบัญชี | การเข้าถึง API |
|---|---|
| บัญชีธุรกิจ | เข้าถึง API ได้เต็มรูปแบบ |
| บัญชี Creator | เข้าถึง API ได้เต็มรูปแบบ |
| บัญชีส่วนตัว | ไม่สามารถเข้าถึง API ได้ (ต้องแปลง) |
| บัญชีส่วนตัว (ตั้งค่าเป็นส่วนตัว) | ข้อมูลเชิงลึกจำกัด |
ภาพรวมสถาปัตยกรรม API
Instagram ใช้โครงสร้าง Facebook Graph API:
https://graph.facebook.com/v18.0/
เปรียบเทียบเวอร์ชัน API
| เวอร์ชัน | สถานะ | วันสิ้นสุด | กรณีการใช้งาน |
|---|---|---|---|
| v18.0 | ปัจจุบัน | มีนาคม 2026 | การผสานรวมใหม่ทั้งหมด |
| v17.0 | เลิกใช้งานแล้ว | มกราคม 2026 | การผสานรวมที่มีอยู่ |
| v16.0 | ยกเลิกแล้ว | หมดอายุ | ห้ามใช้ |
Facebook ออกเวอร์ชันใหม่ทุกไตรมาส ควรใช้เวอร์ชันเสถียรล่าสุดเสมอ
เริ่มต้นใช้งาน: การตั้งค่าการยืนยันตัวตน
ขั้นตอนที่ 1: สร้างบัญชี Facebook Developer
ก่อนเข้าถึง API:
- เยี่ยมชม Facebook Developers Portal
- เข้าสู่ระบบด้วยบัญชี Facebook
- สร้างแอป Facebook (ประเภท: ธุรกิจ)
- เพิ่มผลิตภัณฑ์ Instagram Graph API
ขั้นตอนที่ 2: เชื่อมโยงบัญชี Instagram Business
เชื่อมต่อ Instagram กับเพจ Facebook:
- ไปที่ Facebook Page Settings > Instagram
- คลิก เชื่อมต่อบัญชี
- เข้าสู่ระบบ Instagram และให้สิทธิ์
- ยืนยันว่าบัญชี Instagram Business ถูกเชื่อมโยงแล้ว
หมายเหตุ: บัญชี Instagram ส่วนตัวไม่สามารถใช้ Graph API ได้ โปรดแปลงเป็นบัญชี Business หรือ Creator ในการตั้งค่า Instagram
ขั้นตอนที่ 3: รับ Access Tokens
สร้าง User Access Token:
const FB_APP_ID = process.env.FB_APP_ID;
const FB_APP_SECRET = process.env.FB_APP_SECRET;
const FB_REDIRECT_URI = process.env.FB_REDIRECT_URI;
// Build authorization URL
const getAuthUrl = (state) => {
const params = new URLSearchParams({
client_id: FB_APP_ID,
redirect_uri: FB_REDIRECT_URI,
scope: 'instagram_basic,instagram_content_publish,instagram_manage_comments,instagram_manage_insights,pages_read_engagement',
state: state
});
return `https://www.facebook.com/v18.0/dialog/oauth?${params.toString()}`;
};
สิทธิ์ที่จำเป็น
| สิทธิ์ | คำอธิบาย |
|---|---|
instagram_basic |
ข้อมูลโปรไฟล์พื้นฐาน, รายการสื่อ |
instagram_content_publish |
เผยแพร่รูปภาพ, วิดีโอ, แคโรเซล |
instagram_manage_comments |
อ่าน/เขียนความคิดเห็น |
instagram_manage_insights |
เข้าถึงข้อมูลวิเคราะห์ |
pages_read_engagement |
การเข้าถึงเพจเพื่อเผยแพร่ |
pages_manage_posts |
เผยแพร่ไปยังเพจที่เชื่อมต่อ |
ขั้นตอนที่ 4: แลกเปลี่ยนโทเค็นเป็น Long-Lived Token
โทเค็นระยะสั้นจะหมดอายุใน 1 ชั่วโมง แลกเปลี่ยนเป็นโทเค็นระยะยาว (60 วัน):
const exchangeForLongLivedToken = async (shortLivedToken) => {
const response = await fetch(
`https://graph.facebook.com/v18.0/oauth/access_token?` +
`grant_type=fb_exchange_token&` +
`client_id=${FB_APP_ID}&` +
`client_secret=${FB_APP_SECRET}&` +
`fb_exchange_token=${shortLivedToken}`
);
const data = await response.json();
return data;
};
// การใช้งาน
const longLivedToken = await exchangeForLongLivedToken(shortLivedToken);
console.log(`โทเค็นหมดอายุ: ${new Date(longLivedToken.expires_at * 1000)}`);
ขั้นตอนที่ 5: รับ ID บัญชี Instagram Business
ดึงบัญชี Instagram ที่เชื่อมต่อ:
const getInstagramAccountId = async (pageId, accessToken) => {
const response = await fetch(
`https://graph.facebook.com/v18.0/${pageId}?fields=instagram_business_account&access_token=${accessToken}`
);
const data = await response.json();
return data.instagram_business_account.id;
};
// การใช้งาน
const igAccountId = await getInstagramAccountId('12345678', accessToken);
console.log(`ID บัญชี Instagram: ${igAccountId}`);
ขั้นตอนที่ 6: ทำการเรียกใช้ API ที่มีการยืนยันตัวตน
สร้างไคลเอนต์ API ที่นำกลับมาใช้ใหม่ได้:
const IG_BASE_URL = 'https://graph.facebook.com/v18.0';
const instagramRequest = async (endpoint, params = {}) => {
const url = new URL(`${IG_BASE_URL}${endpoint}`);
url.searchParams.append('access_token', process.env.INSTAGRAM_ACCESS_TOKEN);
Object.entries(params).forEach(([key, value]) => {
url.searchParams.append(key, value);
});
const response = await fetch(url.toString());
if (!response.ok) {
const error = await response.json();
throw new Error(`Instagram API Error: ${error.error.message}`);
}
return response.json();
};
// การใช้งาน
const account = await instagramRequest(`/me`);
console.log(`บัญชี Instagram: ${account.username}`);
การเผยแพร่เนื้อหา
การเผยแพร่รูปภาพ
โพสต์รูปภาพลง Instagram:
const publishPhoto = async (igAccountId, photoData) => {
// ขั้นตอนที่ 1: สร้างคอนเทนเนอร์สื่อ
const containerResponse = await instagramRequest(`/${igAccountId}/media`, {
method: 'POST',
image_url: photoData.imageUrl,
caption: photoData.caption,
location_id: photoData.locationId, // ไม่บังคับ
is_carousel_item: 'false'
});
const creationId = containerResponse.id;
// ขั้นตอนที่ 2: เผยแพร่สื่อ
const publishResponse = await instagramRequest(`/${igAccountId}/media_publish`, {
method: 'POST',
creation_id: creationId
});
return publishResponse;
};
// การใช้งาน
const post = await publishPhoto({
igAccountId: '17841400000000000',
imageUrl: 'https://example.com/image.jpg',
caption: 'Excited to announce our new product! 🚀 #launch #innovation',
locationId: '123456789' // ไม่บังคับ
});
console.log(`ID สื่อที่เผยแพร่: ${post.id}`);
การเผยแพร่วิดีโอ
โพสต์วิดีโอลง Instagram:
const publishVideo = async (igAccountId, videoData) => {
// ขั้นตอนที่ 1: สร้างคอนเทนเนอร์สื่อ
const containerResponse = await instagramRequest(`/${igAccountId}/media`, {
method: 'POST',
video_url: videoData.videoUrl,
cover_url: videoData.coverUrl, // รูปขนาดย่อ (thumbnail) เสริม
caption: videoData.caption,
media_type: 'REELS', // หรือ 'VIDEO' สำหรับฟีด
share_to_feed: 'true' // สำหรับ Reels
});
const creationId = containerResponse.id;
// รอการประมวลผลวิดีโอ (ตรวจสอบสถานะจนกว่าจะเป็น EXPIRED หรือ FINISHED)
await waitForVideoProcessing(creationId);
// ขั้นตอนที่ 2: เผยแพร่สื่อ
const publishResponse = await instagramRequest(`/${igAccountId}/media_publish`, {
method: 'POST',
creation_id: creationId
});
return publishResponse;
};
const waitForVideoProcessing = async (creationId, maxAttempts = 30) => {
for (let i = 0; i < maxAttempts; i++) {
const status = await instagramRequest(`/${creationId}`);
if (status.status_code === 'FINISHED') {
return true;
} else if (status.status_code === 'EXPIRED') {
throw new Error('การประมวลผลวิดีโอหมดอายุ');
}
await new Promise(resolve => setTimeout(resolve, 2000));
}
throw new Error('หมดเวลาการประมวลผลวิดีโอ');
};
การเผยแพร่แคโรเซล (รูปภาพ/วิดีโอหลายรายการ)
โพสต์รายการสื่อหลายรายการในโพสต์เดียว:
const publishCarousel = async (igAccountId, carouselData) => {
const children = [];
// ขั้นตอนที่ 1: สร้างแต่ละรายการแคโรเซล
for (const item of carouselData.items) {
const containerResponse = await instagramRequest(`/${igAccountId}/media`, {
method: 'POST',
[item.type === 'video' ? 'video_url' : 'image_url']: item.url,
caption: item.caption || '',
is_carousel_item: 'true'
});
children.push(containerResponse.id);
}
// ขั้นตอนที่ 2: สร้างคอนเทนเนอร์แคโรเซลพร้อมรายการย่อย
const carouselContainerResponse = await instagramRequest(`/${igAccountId}/media`, {
method: 'POST',
media_type: 'CAROUSEL',
children: children.join(','),
caption: carouselData.caption
});
const creationId = carouselContainerResponse.id;
// ขั้นตอนที่ 3: เผยแพร่แคโรเซล
const publishResponse = await instagramRequest(`/${igAccountId}/media_publish`, {
method: 'POST',
creation_id: creationId
});
return publishResponse;
};
// การใช้งาน
const carousel = await publishCarousel('17841400000000000', {
caption: 'Product showcase 2026',
items: [
{ type: 'image', url: 'https://example.com/img1.jpg', caption: 'Product 1' },
{ type: 'image', url: 'https://example.com/img2.jpg', caption: 'Product 2' },
{ type: 'video', url: 'https://example.com/vid1.mp4', caption: 'Demo' }
]
});
ประเภทสื่อ
| ประเภทสื่อ | พารามิเตอร์ | กรณีการใช้งาน |
|---|---|---|
IMAGE |
image_url, caption | โพสต์รูปภาพ |
VIDEO |
video_url, cover_url, caption | โพสต์วิดีโอ |
REELS |
video_url, cover_url, caption, share_to_feed | Reels |
CAROUSEL |
children (array), caption | สื่อหลายรายการ |
การเรียกดูสื่อและข้อมูลเชิงลึก
การเรียกดูสื่อของผู้ใช้
ดึงสื่อที่เผยแพร่:
const getUserMedia = async (igAccountId, limit = 25) => {
const response = await instagramRequest(`/${igAccountId}/media`, {
fields: 'id,caption,media_type,media_url,permalink,timestamp,like_count,comments_count',
limit: limit.toString()
});
return response;
};
// การใช้งาน
const media = await getUserMedia('17841400000000000');
media.data.forEach(item => {
console.log(`${item.media_type}: ${item.caption}`);
console.log(`ไลค์: ${item.like_count}, ความคิดเห็น: ${item.comments_count}`);
console.log(`URL: ${item.permalink}`);
});
การเรียกดูข้อมูลเชิงลึกของสื่อ
ดึงข้อมูลวิเคราะห์สำหรับสื่อเฉพาะ:
const getMediaInsights = async (mediaId) => {
const response = await instagramRequest(`/${mediaId}/insights`, {
fields: 'impressions,reach,engagement,saved,video_views,profile_visits,follows'
});
return response;
};
// การใช้งาน
const insights = await getMediaInsights('17890000000000000');
insights.data.forEach(metric => {
console.log(`${metric.name}: ${metric.values[0].value}`);
});
เมตริกข้อมูลเชิงลึกที่พร้อมใช้งาน
| เมตริก | คำอธิบาย | ประเภทสื่อ |
|---|---|---|
impressions |
ยอดดูทั้งหมด | ทั้งหมด |
reach |
บัญชีที่ไม่ซ้ำกันที่เข้าถึง | ทั้งหมด |
engagement |
ไลค์ + ความคิดเห็น + การบันทึก | ทั้งหมด |
saved |
จำนวนครั้งที่บันทึก | ทั้งหมด |
video_views |
ยอดดูวิดีโอ (3+ วินาที) | วิดีโอ, Reels |
plays |
ยอดเล่นวิดีโอทั้งหมด | วิดีโอ, Reels |
profile_visits |
การเข้าชมโปรไฟล์จากโพสต์ | ทั้งหมด |
follows |
ผู้ติดตามจากโพสต์ | ทั้งหมด |
comments |
จำนวนความคิดเห็น | ทั้งหมด |
like_count |
จำนวนไลค์ | ทั้งหมด |
การเรียกดูข้อมูลเชิงลึกของบัญชี
ดึงข้อมูลวิเคราะห์รวมของบัญชี:
const getAccountInsights = async (igAccountId, metricNames, since = null, until = null) => {
const params = {
metric: metricNames.join(','),
period: 'day'
};
if (since) params.since = since;
if (until) params.until = until;
const response = await instagramRequest(`/${igAccountId}/insights`, params);
return response;
};
// การใช้งาน - รับเมตริกย้อนหลัง 30 วัน
const accountInsights = await getAccountInsights(
'17841400000000000',
['impressions', 'reach', 'profile_views', 'email_contacts', 'website_clicks'],
'2026-02-23',
'2026-03-25'
);
accountInsights.data.forEach(metric => {
console.log(`${metric.name}:`);
metric.values.forEach(value => {
console.log(` ${value.end_time}: ${value.value}`);
});
});
เมตริกระดับบัญชี
| เมตริก | คำอธิบาย |
|---|---|
impressions |
ยอดดูโปรไฟล์ + เนื้อหาทั้งหมด |
reach |
บัญชีที่ไม่ซ้ำกันที่เข้าถึง |
profile_views |
การเข้าชมโปรไฟล์ |
website_clicks |
การคลิกลิงก์ในประวัติ |
email_contacts |
การแตะปุ่มอีเมล |
phone_call_clicks |
การแตะปุ่มโทรศัพท์ |
text_message_clicks |
การแตะปุ่ม SMS |
get_directions_clicks |
การคลิกที่อยู่ |
follower_count |
ผู้ติดตามทั้งหมด |
audience_city |
เมืองของผู้ติดตาม |
audience_country |
ประเทศของผู้ติดตาม |
audience_gender_age |
ข้อมูลประชากรโดยละเอียด |
การจัดการความคิดเห็น
การเรียกดูความคิดเห็น
ดึงความคิดเห็นบนสื่อ:
const getMediaComments = async (mediaId, limit = 50) => {
const response = await instagramRequest(`/${mediaId}/comments`, {
fields: 'id,text,timestamp,username,hidden',
limit: limit.toString()
});
return response;
};
// การใช้งาน
const comments = await getMediaComments('17890000000000000');
comments.data.forEach(comment => {
console.log(`@${comment.username}: ${comment.text}`);
console.log(`ซ่อนแล้ว: ${comment.hidden}`);
});
การตอบกลับความคิดเห็น
โพสต์ตอบกลับความคิดเห็น:
const replyToComment = async (mediaId, commentId, replyText) => {
const response = await instagramRequest(`/${mediaId}/comments`, {
method: 'POST',
response_to: commentId,
message: replyText
});
return response;
};
// การใช้งาน
const reply = await replyToComment(
'17890000000000000',
'17900000000000000',
'Thank you for your interest! Check your DM for details.'
);
console.log(`ตอบกลับแล้ว: ${reply.id}`);
การซ่อนความคิดเห็น
ซ่อนความคิดเห็นที่ไม่เหมาะสม:
const hideComment = async (commentId) => {
const response = await instagramRequest(`/${commentId}`, {
method: 'POST',
hide: 'true'
});
return response;
};
// การใช้งาน
await hideComment('17900000000000000');
console.log('ความคิดเห็นถูกซ่อน');
การลบความคิดเห็น
ลบความคิดเห็นที่เป็นสแปมหรือไม่เหมาะสม:
const deleteComment = async (commentId) => {
await instagramRequest(`/${commentId}`, {
method: 'DELETE'
});
console.log('ความคิดเห็นถูกลบ');
};
Webhooks
การกำหนดค่า Webhooks
ตั้งค่า webhooks สำหรับการแจ้งเตือนแบบเรียลไทม์:
const subscribeToWebhooks = async (appId, pageId, accessToken) => {
// Subscribe to Instagram events
const response = await fetch(
`https://graph.facebook.com/v18.0/${appId}/subscriptions`,
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
object: 'instagram',
callback_url: 'https://myapp.com/webhooks/instagram',
verify_token: process.env.WEBHOOK_VERIFY_TOKEN,
access_token: accessToken,
fields: ['comments', 'mentions', 'message_reactions']
})
}
);
return response.json();
};
การจัดการ Webhooks
const express = require('express');
const app = express();
// ตรวจสอบการสมัครสมาชิก webhook
app.get('/webhooks/instagram', (req, res) => {
const mode = req.query['hub.mode'];
const token = req.query['hub.verify_token'];
const challenge = req.query['hub.challenge'];
if (mode === 'subscribe' && token === process.env.WEBHOOK_VERIFY_TOKEN) {
console.log('Webhook ได้รับการยืนยัน');
res.status(200).send(challenge);
} else {
res.status(403).send('การยืนยันล้มเหลว');
}
});
// จัดการเหตุการณ์ webhook
app.post('/webhooks/instagram', express.json(), async (req, res) => {
const body = req.body;
if (body.object !== 'instagram') {
return res.status(404).send('ไม่พบ');
}
for (const entry of body.entry) {
const igId = entry.id;
const changes = entry.changes;
for (const change of changes) {
switch (change.field) {
case 'comments':
await handleNewComment(change.value);
break;
case 'mentions':
await handleMention(change.value);
break;
case 'message_reactions':
await handleReaction(change.value);
break;
}
}
}
res.status(200).send('OK');
});
async function handleNewComment(data) {
console.log(`ความคิดเห็นใหม่บนสื่อ ${data.media_id}`);
console.log(`จาก: ${data.from_id}`);
console.log(`ข้อความ: ${data.text}`);
// ตอบกลับอัตโนมัติหรือกลั่นกรอง
if (isSpam(data.text)) {
await hideComment(data.id);
}
}
ฟิลด์ Webhook
| ฟิลด์ | ทริกเกอร์ |
|---|---|
comments |
ความคิดเห็นใหม่หรือการตอบกลับ |
mentions |
ผู้ใช้กล่าวถึงบัญชี |
message_reactions |
ปฏิกิริยาต่อสตอรี่ |
story_status |
การตอบกลับ/การดูสตอรี่ |
การจำกัดอัตราการเรียกใช้
ทำความเข้าใจเกี่ยวกับการจำกัดอัตราการเรียกใช้
Instagram Graph API กำหนดการจำกัด:
- 200 ครั้งต่อชั่วโมงต่อแอป (แชร์ระหว่างผู้ใช้ทุกคน)
- Business Discovery: 200 ครั้งต่อชั่วโมงต่อผู้ใช้
- การเผยแพร่เนื้อหา: จำกัดตามประเภทการกระทำ
การเกินขีดจำกัดจะส่งผลให้เกิด HTTP 400 พร้อมรหัสข้อผิดพลาดย่อย 613
แนวทางปฏิบัติที่ดีที่สุดสำหรับการจำกัดอัตราการเรียกใช้
- แคชการตอบสนอง - อย่าดึงข้อมูลที่ไม่เปลี่ยนแปลงซ้ำ
- ส่งคำขอแบบกลุ่ม - ใช้การขยายฟิลด์เพื่อลดจำนวนการเรียกใช้
- ใช้ webhooks - การอัปเดตแบบเรียลไทม์แทนการสำรวจข้อมูล
- ใช้กลไก Backoff - Exponential backoff เมื่อเกิดข้อผิดพลาด 429
const makeRateLimitedRequest = async (endpoint, params = {}, maxRetries = 3) => {
for (let attempt = 1; attempt <= maxRetries; attempt++) {
try {
const response = await instagramRequest(endpoint, params);
return response;
} catch (error) {
if (error.message.includes('429') && attempt < maxRetries) {
const delay = Math.pow(2, attempt) * 1000;
console.log(`ถูกจำกัดอัตราการเรียกใช้ กำลังลองใหม่ใน ${delay} มิลลิวินาที...`);
await new Promise(resolve => setTimeout(resolve, delay));
} else {
throw error;
}
}
}
};
การแก้ไขปัญหาทั่วไป
ปัญหา: โทเค็น OAuth หมดอายุ
อาการ: ได้รับข้อผิดพลาด “Invalid OAuth access token”
วิธีแก้ไข:
- ใช้การรีเฟรชโทเค็นก่อนหมดอายุ 60 วัน
- จัดเก็บวันหมดอายุของโทเค็นและแจ้งเตือนก่อนหมดอายุ
- ยืนยันตัวตนผู้ใช้ใหม่หากโทเค็นหมดอายุ
ปัญหา: การเผยแพร่สื่อล้มเหลว
อาการ: การเผยแพร่ส่งคืนข้อผิดพลาด
วิธีแก้ไข:
- ตรวจสอบว่า URL รูปภาพสามารถเข้าถึงได้แบบสาธารณะ (ไม่จำเป็นต้องมีการยืนยันตัวตน)
- ตรวจสอบรูปแบบรูปภาพ (JPEG, PNG) และขนาด (น้อยกว่า 8MB)
- ตรวจสอบว่าวิดีโอเป็นรูปแบบ MP4, น้อยกว่า 1GB, น้อยกว่า 90 วินาที
- รอการประมวลผลวิดีโอก่อนเผยแพร่
ปัญหา: ข้อมูลเชิงลึกไม่พร้อมใช้งาน
อาการ: Insights API ส่งคืนข้อมูลว่างเปล่า
วิธีแก้ไข:
- ตรวจสอบว่าบัญชีเป็น Business หรือ Creator (ไม่ใช่ส่วนตัว)
- รอ 24-48 ชั่วโมงเพื่อให้ข้อมูลเชิงลึกปรากฏ
- ตรวจสอบว่าบัญชีมีกิจกรรมเพียงพอ
รายการตรวจสอบสำหรับการนำไปใช้งานจริง
ก่อนนำไปใช้งานจริง:
- [ ] แปลงบัญชีทดสอบทั้งหมดเป็น Business/Creator
- [ ] ใช้ OAuth 2.0 พร้อมโทเค็นระยะยาว
- [ ] จัดเก็บโทเค็นอย่างปลอดภัยด้วยการเข้ารหัส
- [ ] ใช้การรีเฟรชโทเค็นอัตโนมัติ
- [ ] ตั้งค่าปลายทาง webhook ด้วย HTTPS
- [ ] เพิ่มการจำกัดอัตราการเรียกใช้และการจัดคิวคำขอ
- [ ] ใช้การจัดการข้อผิดพลาดที่ครอบคลุม
- [ ] เพิ่มการบันทึกสำหรับการเรียกใช้ API ทั้งหมด
- [ ] สร้างเวิร์กโฟลว์การกลั่นกรองเนื้อหา
- [ ] ทดสอบกับบัญชีหลายประเภท
กรณีการใช้งานจริง
เครื่องมือจัดตารางโพสต์โซเชียลมีเดีย
แพลตฟอร์มการตลาดที่ทำให้การโพสต์เป็นไปโดยอัตโนมัติ:
- ความท้าทาย: การโพสต์ด้วยตนเองในบัญชีลูกค้ากว่า 50 บัญชี
- วิธีแก้ไข: การเผยแพร่ตามกำหนดเวลาผ่าน Instagram API
- ผลลัพธ์: ประหยัดเวลาได้ 80%, กำหนดการโพสต์ที่สอดคล้องกัน
การนำไปใช้งานหลัก:
- ปฏิทินเนื้อหาพร้อมการจัดตารางแบบลากและวาง
- เผยแพร่รูปภาพ, วิดีโอ, แคโรเซลอัตโนมัติ
- คำแนะนำแฮชแท็กตามเนื้อหา
การทำให้บริการลูกค้าเป็นไปโดยอัตโนมัติ
แบรนด์อีคอมเมิร์ซที่ทำให้การตอบกลับความคิดเห็นเป็นไปโดยอัตโนมัติ:
- ความท้าทาย: การตอบกลับคำถามลูกค้าช้า
- วิธีแก้ไข: ตอบกลับคำถามทั่วไปอัตโนมัติผ่าน webhook
- ผลลัพธ์: เวลาตอบกลับเฉลี่ย 5 นาที, ความพึงพอใจ 90%
การนำไปใช้งานหลัก:
- การตรวจจับคีย์เวิร์ด (ราคา, ความพร้อมใช้งาน, การจัดส่ง)
- ตอบกลับอัตโนมัติพร้อมลิงก์สินค้า
- ส่งต่อคำถามที่ซับซ้อนไปยังตัวแทนที่เป็นมนุษย์
สรุป
Instagram Graph API ให้การเข้าถึงคุณสมบัติบัญชี Instagram Business และ Creator ได้อย่างครอบคลุม ประเด็นสำคัญ:
- การยืนยันตัวตน Facebook Login OAuth 2.0 พร้อมโทเค็น 60 วัน
- การเผยแพร่เนื้อหารองรับรูปภาพ, วิดีโอ, Reels, แคโรเซล
- Insights API ให้ข้อมูลการมีส่วนร่วม, การเข้าถึง, และข้อมูลประชากร
- Webhooks ช่วยให้สามารถตรวจสอบความคิดเห็นและการกล่าวถึงแบบเรียลไทม์ได้
- ข้อจำกัดอัตราการเรียกใช้ 200 ครั้ง/ชั่วโมงต่อแอป ต้องได้รับการจัดการอย่างรอบคอบ
- Apidog ช่วยให้การทดสอบ API และการทำงานร่วมกันของทีมเป็นไปอย่างราบรื่น
คำถามที่พบบ่อย
ฉันจะเข้าถึง Instagram API ได้อย่างไร?
สร้างบัญชี Facebook Developer, สร้างแอปประเภท Business, เพิ่มผลิตภัณฑ์ Instagram Graph API, และยืนยันตัวตนผ่าน Facebook Login ด้วยสิทธิ์ที่จำเป็น
ฉันสามารถโพสต์ลง Instagram โดยอัตโนมัติได้หรือไม่?
ได้ คุณสามารถใช้ Content Publishing API เพื่อเผยแพร่รูปภาพ, วิดีโอ, Reels, และแคโรเซลไปยังบัญชี Business และ Creator ได้
บัญชี Instagram ประเภทใดบ้างที่รองรับ API นี้?
เฉพาะบัญชี Business และ Creator เท่านั้นที่มีสิทธิ์เข้าถึง API ได้เต็มรูปแบบ บัญชีส่วนตัวมีการเข้าถึง API ที่จำกัดหรือไม่สามารถเข้าถึงได้เลย
ฉันจะเรียกดูความคิดเห็นจาก Instagram ได้อย่างไร?
ใช้ปลายทาง Comments (/{media-id}/comments) เพื่อดึงความคิดเห็นบนสื่อเฉพาะ Webhooks ให้การแจ้งเตือนแบบเรียลไทม์
ข้อจำกัดอัตราการเรียกใช้ของ Instagram คืออะไร?
Instagram Graph API อนุญาตให้เรียกใช้ 200 ครั้งต่อชั่วโมงต่อแอป บางปลายทางมีข้อจำกัดเพิ่มเติมต่อผู้ใช้
ฉันสามารถเผยแพร่ Stories ผ่าน API ได้หรือไม่?
ได้ Stories สามารถเผยแพร่ได้โดยใช้ขั้นตอนการเผยแพร่เนื้อหาเดียวกันกับโพสต์ในฟีด
ฉันจะเข้าถึง Instagram Insights ได้อย่างไร?
ขอสิทธิ์ <code>instagram_manage_insights</code> ในระหว่างกระบวนการ OAuth ใช้ปลายทาง Insights เพื่อดึงเมตริกสำหรับสื่อและบัญชี
ฉันสามารถตอบกลับความคิดเห็นอัตโนมัติได้หรือไม่?
ได้ คุณสามารถใช้ Comments API เพื่อโพสต์ตอบกลับ แบรนด์จำนวนมากใช้สิ่งนี้สำหรับการตอบกลับบริการลูกค้าอัตโนมัติ
Top comments (0)