-
hunghung
Private
Em đang phát triển để bắn data sang xfr = api, hiện tại đã tạo được thread và đang vướng phần tạo attachment, đọc hết các document mà em mãi chưa xử lý được. Bác nào từng phát triển có thể cho em xin 1 mẫu code php được k.
Hiện tại code của em như sau:
luôn xuất hiện lỗi :
stdClass Object ( [errors] => Array ( [0] => stdClass Object (
Nếu được cho em xin 1 demo. Cảm ơn mọi người rất nhiều
Hiện tại code của em như sau:
Mã:
$file = file_get_contents(file);
$apikey = 'dfhsdg';
$method = CURLOPT_POST;
// tạo mới key :
$data = [
"type" => 'threads',
"context" => 'node_id=10',
"attachment" => $file,
];
// tạo key
$rest_api_url = 'http://exampleurl.vn/api/attachments/new-key';
$result = $this->curl_api($api_key, $rest_api_url, $method, $data);
//
function curl_api ($api_key, $rest_api_url, $method, $data){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $rest_api_url);
curl_setopt($ch, CURLOPT_ENCODING, '');
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
if ($method == CURLOPT_POST) {
curl_setopt($ch, $method, 1);
}
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$headers = array(
'Content-Type: multipart/form-data',
'XF-Api-Key: ' . $apiKey,
);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
curl_close($ch);
return;
}
// tạo mới attachment
$bta = [
"key" => $keys,
"attachment" => $file
];
$rest_api_url = 'http://examplurl.vn/api/attachments';
$result = $this->curl_api($api_key, $rest_api_url, $method, $bta);
luôn xuất hiện lỗi :
stdClass Object ( [errors] => Array ( [0] => stdClass Object (
Mã:
=> required_input_missing [message] => Required input missing: type [params] => stdClass Object ( [missing] => Array ( [0] => type ) ) ) ) )