<?php
// Define the API endpoint
$apiUrl = "https://h...content-available-to-author-only...n.app/text/v1/check";
// The text you want to analyze
$text = "Dies ist ein nicht-toxischer Beispieltext.";
// Prepare the data payload
"text" => $text
);
// Encode the data to JSON
// Set your access token here (or load it from file/environment)
$bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiVGVzdGVyIiwicm9sZSI6InRlc3Rfc3Vic2NyaXB0aW9uIiwiZXhwIjoxNzYzMTAzMjQzfQ.njDRUR_GW-IdZ29AOSkcm69N-7zRzX6Zd3mnQL2uekU";
if (!$bearerToken) {
echo "Error: Bearer token not set. Please set the BEARER_TOKEN environment variable.\n";
}
// Initialize cURL and set options
'Content-Type: application/json',
'Authorization: Bearer ' . $bearerToken
));
// Execute the request
// Check for cURL errors
}
// Get the HTTP status code
// Close the cURL session
// Decode the response
// Response handling
if ($httpStatus == 200) {
// Successful response
echo "Request was successful.<br>";
// This shows the complete response data:
echo "Response Data:<br>";
// This is the estimated toxicity value:
$toxicity = $responseData['toxicity'];
echo "Toxicity Level:<br>";
echo $toxicity;
} else {
// Error response
echo "Request failed with status code $httpStatus.<br>";
if (isset($responseData['detail'])) { echo "Error Detail: " . $responseData['detail'] . "<br>";
} else {
echo "Response Body:<br>";
}
}
?>
PD9waHAKLy8gRGVmaW5lIHRoZSBBUEkgZW5kcG9pbnQKJGFwaVVybCA9ICJodHRwczovL2guLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLm4uYXBwL3RleHQvdjEvY2hlY2siOwoKLy8gVGhlIHRleHQgeW91IHdhbnQgdG8gYW5hbHl6ZQokdGV4dCA9ICJEaWVzIGlzdCBlaW4gbmljaHQtdG94aXNjaGVyIEJlaXNwaWVsdGV4dC4iOwoKLy8gUHJlcGFyZSB0aGUgZGF0YSBwYXlsb2FkCiRkYXRhID0gYXJyYXkoCiAgICAidGV4dCIgPT4gJHRleHQKKTsKCi8vIEVuY29kZSB0aGUgZG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