Utopian Moderators & Supervisors is a Chrome Extension that has iterated for 12 versions, however, sadly, since last time Utopian revokes for all API calls the Chrome Extension is virtually dead i.e. all API calls to https://api.utopian.io/api
return 500 internal server error.
I submitted a support ticket asking for the utopian API key but got rejected because:
A API key must not be given out to end users and/or other developers.
An API Key is bind to one ore more domains. From which domain/domains will you send the requests. At the moment we can only provide API keys suiteable for ajax requests made from websites in a browser.
Luckily, at the London Cryptocurrency Show I met @wehmoen who is the leading developer (staff) at @utopian-io therefore I managed to persuade him giving me the API key by proposing that I will wrap the API key on my server and change all API calls in the chrome extension to my API server, where I will hide all the API key/secret in my server.
Therefore, with the changes commited here, the Utopian Moderators v0.0.13 is back to life!
You can install the extension at Chrome Webstore. For Opera browsers, the workaround is to first installthis and similarly for Firefox, you can install Chrome Store Foxified before you install Utopian Moderators & Supervisors.
API wrapping in PHP
<?php
/*
utopian api wrapper at server side
thanks to @wehmoen for providing me api key
*/
define("ORIGIN", "");
define("API_KEY", "");
define("API_KEY_ID", "");
function CallAPI($url, &$error, $data = null, $headers = null) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($headers) {
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
$response = curl_exec($curl);
$data = json_decode($response);
/* Check for 404 (file not found). */
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
// Check the HTTP Status code
switch ($httpCode) {
case 200:
$error = 200;
break;
case 404:
$error = 404;
break;
case 500:
$error = 500;
break;
case 502:
$error = 502;
break;
case 503:
$error = 503;
break;
default:
$error = $httpCode;
break;
}
curl_close($curl);
return ($data);
}
$api = $_GET['api'] ?? '';
if (!$api) {
die();
}
// avoid hacking to get the keys
$host = strtolower(parse_url($api, PHP_URL_HOST));
if ($host != 'api.utopian.io') {
die();
}
$headers = array("Origin: " . ORIGIN, "x-api-key: " . API_KEY, "x-api-key-id: " . API_KEY_ID);
$err = '';
$data = CallAPI($api, $err, null, $headers);
header("Access-Control-Allow-Origin: *");
header('Content-Type: application/json');
if ($err === 200) {
die(json_encode($data));
} else {
die(json_encode(array("error" => $err, "raw" => $data)));
}
PS: just confirmed with @wehmoen the https://utopian.plus/unreviewedPosts.json
is not working anymore and unfortunately there is currently no suitable API calls for this purpose.
Long live @utopian-io !
Reposted to my blog for better indexing and archiving.
Support me and my work as a witness by
Posted on Utopian.io - Rewarding Open Source Contributors