【发布时间】:2020-08-14 05:17:28
【问题描述】:
在我的这个问题上,我谦卑地来到伟大的开发者面前。向 Firebase 发送 JSON 格式的发布请求。这是我的代码
$token = $_SESSION['token'];
$data = array(
'id' => 156,
'quizName' => $quizName,
'numberOfQuestions' => $numberOfQuestions,
'isTimed' => true,
'numberOfMinutesToComplete' => $numberOfMinutesToComplete,
'targetedClass' => 'Js One',
'subject' => $subject_name,
'schoolLevel' => $schoolLevel,
'questions' => array('question' => $question, 'questionMark' => $marks,
'options' => array('option' => 'A', 'answer'=> $optionA, 'option' => 'B', 'answer'=> $optionB, 'option' => 'C', 'answer' => $optionC, 'option' => 'D', 'answer' => $optionD, 'option' => 'E', 'answer' => $optionE),
'hasImage' => true,
'images' => array('images-1' => 'image-1', 'images-2' => 'image-2'),
'correctionOption' => $correct_option
),
'totalValidMarks' => $totalValidMarks,
'validUntil' => $validUntil
);
// API URL
$url = ' ';
// Create a new cURL resource
$ch = curl_init( $url );
# Setup request to send json via POST.
$payload = json_encode( array( "customer"=> $data ) );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $payload );
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('x-access-token:'.$token, 'Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
# Send request.
$result = curl_exec($ch);
curl_close($ch);
# Print response.
echo "<pre>$result.</pre>";
但我收到一个错误:
"details":[{"message":"\"id\" is required","path":["id"],"type":"any.required","context":{"label ":"id","key":"id"}}]}
【问题讨论】:
-
能否请您链接到 API 文档?有没有可以用来代替 cURL 的 PHP SDK?
-
您建议使用哪个 SDK?
-
这取决于您尝试使用的 Firebase 服务,这就是我要求提供文档链接的原因
-
对不起,我没有及时收到。这就是 API 主体