Revive Utopian Chrome Extension (Wrapping Utopian API Calls)


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 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 suitable 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 install this and similarly for Firefox, you can install Chrome Store Foxified before you install Utopian Moderators & Supervisors.

Utopian API wrapping in PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?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)));
}
<?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)));
}
utopian-chrome-extension-show-more-accounts Revive Utopian Chrome Extension (Wrapping Utopian API Calls) chrome extension php software development SteemIt

utopian-chrome-extension-show-more-accounts

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 !

Support me and my work as a witness by

Thank you!

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
687 words
Last Post: London CryptoCurrency Show - Steem is the NO.1 Blockchain in the world!
Next Post: JobTools Update: Manage Your Favorite Jobs

The Permanent URL is: Revive Utopian Chrome Extension (Wrapping Utopian API Calls)

Leave a Reply