【问题标题】:Error 401: Firebase push notification getting 401 error错误 401:Firebase 推送通知收到 401 错误
【发布时间】:2017-03-30 12:04:26
【问题描述】:

我在尝试通过 https:// URI 访问时遇到以下问题

错误 401:交付的(旧版)服务器密钥无效或发件人无权执行请求。

//发送curl请求的firebase服务器url。

    $url = 'https://fcm.googleapis.com/fcm/send';

    //building headers for the request
    $headers = array(
        'Authorization: key=' . FIREBASE_API_KEY,
        'Content-Type: application/json'
    );

    //Initializing curl to open a connection
    $ch = curl_init();
    //Setting the curl url
    curl_setopt($ch, CURLOPT_URL, $url);
    //setting the method as post
    curl_setopt($ch, CURLOPT_PORT, 443);
    curl_setopt($ch, CURLOPT_POST, true);        
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    //disabling ssl support
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    //adding headers 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    //adding the fields in json format 
    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
    //finally executing the curl request 
    $result = curl_exec($ch);
    /*if ($result === FALSE) {
        die('Curl failed: ' . curl_error($ch));
    }*/        
    $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    if ($status != 201) {
        echo "Error123: call to URL $url failed with status $status, response $result, curl_error " . curl_error($ch) . ", curl_errno " . curl_errno($ch) . '<br>';
    }

    //Now close the connection
    curl_close($ch);

【问题讨论】:

  • 谁能提供解决方案?

标签: php curl firebase firebase-authentication firebase-cloud-messaging


【解决方案1】:

从 firebase 获得解决方案(域 SSL 问题)......并且工作完美!

【讨论】:

  • 能否说得更具体些?
  • @megalucio 存在一些域验证问题,经谷歌验证后运行正常..
猜你喜欢
  • 2014-08-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-22
  • 1970-01-01
相关资源
最近更新 更多