-
Notifications
You must be signed in to change notification settings - Fork 1
/
igPostMessage.gs
75 lines (59 loc) · 2.51 KB
/
igPostMessage.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/**
* @reference https://developers.facebook.com/docs/instagram-api/guides/content-publishing
*/
//建立圖片容器
const createIgPostContent = async(message, imageUrl) =>{
const url = `https://graph.facebook.com/v20.0/${instaBusinessId}/media?access_token=${FACEBOOK_TOKEN}`;
const data = {
image_url: imageUrl ? imageUrl :'https://res.cloudinary.com/startup-grind/image/upload/c_fill,dpr_2,f_auto,g_center,h_200,q_auto:good,w_200/v1/gcs/platform-data-goog/event_banners/gdev-eccosystems-bevy-chapters-thumbnail_x4z1EBy.png', //對於圖像,將變數設為 image_url,對於視頻,將變數設為 video_url。
caption: message, //在此插入您要發佈的文字
media_type: '' //如果投稿僅包含圖片,則將值設置為 "空";如果投稿僅包含影片,則將值設置為 "REELS";如果投稿包含故事,則將值設置為 "STORIES"。
}
const options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
const response = UrlFetchApp.fetch(url, options);
const reaponseData = JSON.parse(response.getContentText());
const containerId = reaponseData.id
return containerId
}
// 發布圖片容器(發文)
const sendIGPost = async(containerId) =>{
const url = `https://graph.facebook.com/v20.0/${instaBusinessId}/media_publish?access_token=${FACEBOOK_TOKEN}`;
const data = {
creation_id: containerId,
}
const options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
const response = UrlFetchApp.fetch(url, options);
const reaponseData = JSON.parse(response.getContentText());
const postId = reaponseData.id
return postId
}
/**
* 自動IG貼文下留言
* @reference: https://developers.facebook.com/docs/instagram-api/reference/ig-media/comments?locale=zh_TW
*/
const sendIGMessage = async(IgMediaId, blogUrl) =>{
const url = `https://graph.facebook.com/v20.0/${IgMediaId}/comments?access_token=${FACEBOOK_TOKEN}`;
const data = {
"message": `歡迎到原文查看詳細訊息:\n ${blogUrl}`,
}
const options = {
'method' : 'post',
'contentType': 'application/json',
// Convert the JavaScript object to a JSON string.
'payload' : JSON.stringify(data)
};
const response = UrlFetchApp.fetch(url, options);
const reaponseData = JSON.parse(response.getContentText());
const postId = reaponseData.id
return postId
}