dongwen7283 2017-03-30 12:04
浏览 167

错误401:Firebase推送通知获取401错误

I'm facing the following issue with firebase when tried to access through https:// URI but same code works fine with http:// URI:

Error 401: Invalid (legacy) Server-key delivered or Sender is not authorized to perform a request.

//firebase server url to send the curl request.

    $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);
  • 写回答

1条回答 默认 最新

  • dsq30861 2017-03-31 12:55
    关注

    Got the solution from firebase(Domain SSL issue)...and working perfectly!

    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧