簡體   English   中英

FCM 推送通知 - 圖片不推送

[英]FCM push notification - image not push

我有一個問題,我正在嘗試通過http發送 FCM 通知。 當我發送以下有效負載時:

{
     "notification" : {
         "body" : "test Notification",
         "title": "test Notification",
         "image" : "https://www.fillmurray.com/640/360"
     },


"to":"firebasetoken",
"priority":"high"

}

我在移動設備上收到通知,但通知僅包含標題和正文。 我嘗試將圖像更改為 imageurl 但這也不起作用。

我想如下顯示我的通知。

在此處輸入圖像描述

我將不勝感激。 我在去年年初嘗試過,這個有效載荷很好。

這是因為您使用的是不支持圖像有效負載的舊式 HTTP API。 嘗試遷移到 HTTP v1 API,您將能夠發送圖像負載。 按照這些鏈接。 遷移指南 在通知負載中發送圖像

遷移到 HTTP v1 時,您將需要 oAuth 令牌,如果您不知道如何生成它,我將在此處提供分步指南。

要創建 oAuth 令牌,請按照以下步驟操作。
步驟 1. 從 firebase 控制台獲取 serviceaccount json 文件。
轉到 firebase 控制台 -> 項目設置 -> 服務帳戶選項卡,然后單擊生成新的私鑰以下載 json 文件。 json 文件包含一些憑據信息。

步驟 2. 生成令牌
生成令牌將需要使用 node、python 或 java 運行一些程序代碼,在這里我將使用 node.js。
使用以下代碼創建 generatekey.js 文件,並在代碼中更改 json 文件的路徑。

var {google} = require("googleapis");

// Load the service account key JSON file.
var serviceAccount = 
require("path/to/downloaded.json"); //change path to your downloaded json file

// Define the required scopes.
var scopes = [
  "https://www.googleapis.com/auth/userinfo.email",
  "https://www.googleapis.com/auth/firebase.messaging"
 ];

// Authenticate a JWT client with the service account.
var jwtClient = new google.auth.JWT(serviceAccount.client_email,
null,serviceAccount.private_key,scopes);

// Use the JWT client to generate an access token.
jwtClient.authorize(function(error, tokens) {
if (error) {
  console.log("Error making request to generate access token:", 
  error);
} else if (tokens.access_token === null) {
console.log("Provided service account does not have permission to generate access tokens");
} else {
  var accessToken = tokens.access_token;
  console.log(accessToken);

  // See the "Using the access token" section below for information
  // on how to use the access token to send authenticated requests to
  // the Realtime Database REST API.
}
});

使用命令node generatekey.js從終端運行 generatekey.js 文件,它將打印 OAuth2 令牌。

嘗試

const message = {
         "notification" : {
            "body" : "test Notification",
            "title": "test Notification",
         "android": {
            "notification": {
             imageUrl: 'https://www.fillmurray.com/640/360'}
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM