개발/php
php Sendbird 채널 그룹 나가기 curl put 이용
적아38
2024. 5. 28. 15:20
728x90
<?php
// Sendbird API token
$apiToken = 'YOUR_API_TOKEN';
// User IDs array
$userIds = ['USER_ID1', 'USER_ID2']; // Leaving users' IDs
// Group channel URL
$channelUrl = 'GROUP_CHANNEL_URL';
// Sendbird API endpoint to leave a channel
$url = "https://api-XXXXXX.sendbird.com/v3/group_channels/$channelUrl/leave";
// Data to be sent in the request
$data = json_encode(array("user_ids" => $userIds));
// Initialize cURL
$curl = curl_init($url);
// Set cURL options
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
"Api-Token: $apiToken",
"Content-Type: application/json"
));
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// Execute the cURL session
$response = curl_exec($curl);
// Check for cURL errors
if(curl_errno($curl)) {
echo 'Curl error: ' . curl_error($curl);
}
// Close cURL session
curl_close($curl);
// Decode and display the response
$responseData = json_decode($response, true);
print_r($responseData);
?>
728x90