fork download
  1. <?php
  2. // Define the API endpoint
  3. $apiUrl = "https://h...content-available-to-author-only...n.app/text/v1/check";
  4.  
  5. // The text you want to analyze
  6. $text = "Dies ist ein nicht-toxischer Beispieltext.";
  7.  
  8. // Prepare the data payload
  9. $data = array(
  10. "text" => $text
  11. );
  12.  
  13. // Encode the data to JSON
  14. $jsonData = json_encode($data);
  15.  
  16. // Set your access token here (or load it from file/environment)
  17. $bearerToken = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyX2lkIjoiVGVzdGVyIiwicm9sZSI6InRlc3Rfc3Vic2NyaXB0aW9uIiwiZXhwIjoxNzYzMTAzMjQzfQ.njDRUR_GW-IdZ29AOSkcm69N-7zRzX6Zd3mnQL2uekU";
  18.  
  19. if (!$bearerToken) {
  20. echo "Error: Bearer token not set. Please set the BEARER_TOKEN environment variable.\n";
  21. }
  22.  
  23. // Initialize cURL and set options
  24. $ch = curl_init($apiUrl);
  25. curl_setopt($ch, CURLOPT_POST, true);
  26. curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28. curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  29. 'Content-Type: application/json',
  30. 'Authorization: Bearer ' . $bearerToken
  31. ));
  32.  
  33. // Execute the request
  34. $response = curl_exec($ch);
  35.  
  36. // Check for cURL errors
  37. if (curl_errno($ch)) {
  38. echo "cURL Error: " . curl_error($ch) . "<br>";
  39. curl_close($ch);
  40. }
  41.  
  42. // Get the HTTP status code
  43. $httpStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE);
  44.  
  45. // Close the cURL session
  46.  
  47. // Decode the response
  48. $responseData = json_decode($response, true);
  49.  
  50. // Response handling
  51. if ($httpStatus == 200) {
  52.  
  53. // Successful response
  54. echo "Request was successful.<br>";
  55.  
  56. // This shows the complete response data:
  57. echo "Response Data:<br>";
  58. print_r($responseData);
  59.  
  60. // This is the estimated toxicity value:
  61. $toxicity = $responseData['toxicity'];
  62. echo "Toxicity Level:<br>";
  63. echo $toxicity;
  64.  
  65. } else {
  66. // Error response
  67. echo "Request failed with status code $httpStatus.<br>";
  68. if (isset($responseData['detail'])) {
  69. echo "Error Detail: " . $responseData['detail'] . "<br>";
  70. } else {
  71. echo "Response Body:<br>";
  72. print_r($responseData);
  73. }
  74. }
  75. ?>
Success #stdin #stdout 0.04s 26388KB
stdin
Standard input is empty
stdout
cURL Error: Could not resolve host: hs-api-271461042128.europe-west1.run.app<br>