FCM HTTP v1 API 通知編輯器 支援在顯示畫面的酬載中傳送圖片連結 通知將圖片下載至裝置 通知圖片的大小上限為 1MB, 受到原生 Android 限制 圖片支援。
建立傳送要求
在通知傳送要求中,設定下列 AndroidConfig 選項:
- 包含圖片網址的
notification.image
以下範例傳送要求會將通用通知標題傳送至所有平台,但同時也會傳送圖片。以下是 使用者裝置上的視覺效果:
Node.js
const topicName = 'industry-tech';
const message = {
notification: {
title: 'Sparky says hello!'
},
android: {
notification: {
imageUrl: 'https://foo.bar.pizza-monster.png'
}
},
apns: {
payload: {
aps: {
'mutable-content': 1
}
},
fcm_options: {
image: 'https://foo.bar.pizza-monster.png'
}
},
webpush: {
headers: {
image: 'https://foo.bar.pizza-monster.png'
}
},
topic: topicName,
};
getMessaging().send(message)
.then((response) => {
// Response is a message ID string.
console.log('Successfully sent message:', response);
})
.catch((error) => {
console.log('Error sending message:', error);
});
REST
POST https://fcm.googleapis.com/v1/projects/myproject-b5ae1/messages:send HTTP/1.1
Content-Type: application/json
Authorization: Bearer ya29.ElqKBGN2Ri_Uz...HnS_uNreA
{
"message":{
"topic":"industry-tech",
"notification":{
"title":"Sparky says hello!",
},
"android":{
"notification":{
"image":"https://foo.bar/pizza-monster.png"
}
},
"apns":{
"payload":{
"aps":{
"mutable-content":1
}
},
"fcm_options": {
"image":"https://foo.bar/pizza-monster.png"
}
},
"webpush":{
"headers":{
"image":"https://foo.bar/pizza-monster.png"
}
}
}
}
詳情請參閱 HTTP v1 參考說明文件 ,完整瞭解 Ad Exchange 平台中 訊息內文。
如將 notification
設為範例,這個傳送要求可啟用接收用戶端
處理酬載中傳送的圖片。