0

I am using the insert PHP plugin for wordpress to get API data into my pages. so I would replace "" on the last line with "[/insert_php]".

my code

[insert_php]
$url =  'https://www.eobot.com/api.aspx?idspeed=285967&json=true';

$args = array (
    'method' => 'GET'
);

$response = wp_remote_request($url, $args);

$body = wp_remote_retrieve_body($response);
print_r($body);
[/insert_php]

returns

MiningSHA-256:0.00000000;MiningScrypt:0.00000000;CloudSHA-256:12.72592330;Cloud2SHA-256:0.01894240;CloudScrypt:0.00000000;

I have searched, and maybe I am not using the correct terms, and cannot find my solution or answer. I feel like it should be a lot easier than it is. I feel I should be able to take the array from the body and give each its own variable then use the variables to build a table with PHP. Where am I going wrong? Should I first store this in a php file on my server then create a table, then use the insert php function to build the table that way?

2
  • You are trying to access Private API and Private API required account. check this link for more info: eobot.com/developers Commented Jan 4, 2016 at 6:14
  • that is my private account, as you can see it has my userID as it should Commented Jan 4, 2016 at 6:30

2 Answers 2

0

I have tried your code and its working fine for me in local mechine i think you just need to put json_decode for get proper format.

[insert_php]
$url =  'https://www.eobot.com/api.aspx?idspeed=285967&json=true';

$args = array (
    'method' => 'GET'
);

$response = wp_remote_request($url, $args);

$body = wp_remote_retrieve_body($response);
print_r($body);
echo "<pre>";
$data = json_decode($body);
print_r($data);
[/insert_php]

Getting this type of output.

stdClass Object
(
    [MiningSHA-256] => 0.00000000
    [MiningScrypt] => 0.00000000
    [CloudSHA-256] => 12.72656020
    [Cloud2SHA-256] => 0.01894240
    [CloudScrypt] => 0.00000000
)

Please try above code and let me know.

Sign up to request clarification or add additional context in comments.

12 Comments

@ka5050ro some thing wrong with your code. i am getting array like i put in my answer.
maybe I am missing a plugin
@ka5050ro where did you write your code in project ?
its in a page using the edit page function within wordpress
with the output you show I should be able to use this code stackoverflow.com/questions/26213049/…
|
0

I've checked the code and it is doing what you programmed it do. Please check you're using correct API URL and once you're using the correct API URL use json_decode function to decode json data returned API and add once you've correct data converted into array, you can create table.

For example:

<?php
$body = wp_remote_retrieve_body($response);
$table_data = json_decode($body);
$html = array();
if(!empty($table_data)){
  $html[] = '<table>';
  foreach($table_data as $rows){
    $html[] = '<tr>';
    foreach($row as $column){
      $html[] = '<td>'. $column . '</td>';
    }
    $html[] = '</tr>';
  }
  $html ='</table>';
}
$html = implode("\n", $html);
echo $html;
?>

PS: This code is only an example, please adjust it your data.

2 Comments

I guess that's the question I didn't know how to ask was the json decode part. This is the info from the site - Simple, RESTful API - GET and POST supported - Fast, free, unlimited use - Add JSON to any API request by adding &json=true so my question should have been how to put json info into a table?
@ka5050ro Alright, it is simple but answer depends on the contents of returned data and what data you need to show table. Once you've decoded data, it is simple PHP array and you can iterate it to create HTML table. I'm modifying table to write generic answer based on scenario and information available.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.