You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用cURL调用Firebase Cloud Messaging时遇401/403认证权限错误

FCM推送请求出现401/403权限错误

此前可正常通过cURL触发Android应用接收Firebase推送消息,近期按官方文档操作时返回401未授权错误,提示凭证无效;尝试使用OAuth 2.0 token后又返回403权限拒绝错误,涉及未知项目ID,无法找到关联或创建该项目的入口。

相关信息

  • Server key:AAAArxt...CelsCl
  • Firebase项目ID:my-project...485
  • 设备token:fNBu...eHCAgI

获取设备Token的代码

FirebaseMessaging.getInstance().token.addOnSuccessListener { token: String ->
    if (!TextUtils.isEmpty(token)) {
        Log.d("TAG", "retrieve token successful : $token")
    } else {
        Log.w("TAG", "token should not be null...")
    }
}.addOnFailureListener { e: Exception? -> }.addOnCanceledListener {}
.addOnCompleteListener { task: Task<String> ->
    Log.v("TAG", "This is the token : " + task.result)
}

触发推送的cURL请求

curl -X POST -H "Authorization: Bearer AAAArxt...CelsCl" -H "Content-Type: application/json" -d '{
"message":{
   "notification":{
     "title":"FCM Message",
     "body":"This is an FCM Message"
   },
   "token":"fNBu...eHCAgI"
}}' https://fcm.googleapis.com/v1/projects/my-project...485/messages:send

401错误响应

{
  "error": {
    "code": 401,
    "message": "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",
    "status": "UNAUTHENTICATED"
  }
}

使用OAuth 2.0 token后的403错误响应

{
  "error": {
    "code": 403,
    "message": "Permission 'cloudmessaging.messages.create' denied on resource '//cloudresourcemanager.googleapis.com/projects/project-7520...211' (or it may not exist).",
    "status": "PERMISSION_DENIED",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.ErrorInfo",
        "reason": "IAM_PERMISSION_DENIED",
        "domain": "cloudresourcemanager.googleapis.com",
        "metadata": {
          "resource": "projects/project-7520...211",
          "permission": "cloudmessaging.messages.create"
        }
      }
    ]
  }
}

内容的提问来源于stack exchange,提问作者Jim Clermonts

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 17:17:30