php - 收到无效的 JSON 有效负载。未知名称“”:根元素必须是消息
问题描述
我正在使用“使用 REST API 创建动态链接”并为此使用了以下代码。这是使用 google firebase 动态链接 API。
$long_url = "https://etisalatone.page.link/?link=https://www.example.com/reload/10&apn=com.omobio.etisalatone";
$api_url = 'https://firebasedynamiclinks.googleapis.com/v1/shortLinks?key=';
$data = json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ( $ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 'Content-Length: ' . strlen($data)));
curl_setopt($ch, CURLOPT_TIMEOUT, 10); //timeout in seconds
if ($type == 'POST') {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
$api_time_track = microtime();
$result = curl_exec($ch);
$http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
结果产生以下错误:
收到无效的 JSON 有效负载。未知名称“”:根元素必须是消息。
解决方案
推荐阅读
- python - How to identify data type from stdout in nodejs exec method?
- docker - http2: server sent GOAWAY and closed the connection; LastStreamID=73, ErrCode=NO_ERROR, debug="" when pushing docker image to private Artifactory
- sharepoint - How to apply security patch in SharePoint 2010 without upgrading to cumulative update?
- python - Problem with os.makedirs() function with Python3 on Mac OS Catalina
- python - Convert tensorflow to jpeg. Python
- javascript - How can I make a https request to Stripe API with Axios?
- sql-server - Two Problems With DTC
- c++ - 调用虚函数的覆盖导致分段错误
- webpack - nextjs 与 apollo 永远捆绑在开发中
- php - $header 来自:php 中的变量问题