본문 바로가기
개발/php

php Sendbird 채널 그룹 나가기 curl put 이용

by 적아38 2024. 5. 28.
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

'개발 > php' 카테고리의 다른 글

FCM v1 버전  (4) 2024.07.22
코드이그나이터 mogoDB 라이브러리  (0) 2023.04.26
PHP - CURL  (0) 2023.03.28
[php] 지연  (0) 2021.03.02

댓글