import.io JSON data

血红的双手。 提交于 2019-12-04 13:07:54

You need to write this code to output only the string(6) that you're looking for:

<?php

$userGuid = "8f65f01f-c6bc-42a4-914d-879efd159abd";
$apiKey = "private";

// Issues a query request to import.io
function query($connectorGuid, $input, $userGuid, $apiKey) {

    $url = "https://query.import.io/store/connector/" . $connectorGuid . "/_query?_user=" . urlencode($userGuid) . "&_apikey=" . urlencode($apiKey);

    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        "Content-Type: application/json",
        "import-io-client: import.io PHP client",
        "import-io-client-version: 2.0.0"
    ));
    curl_setopt($ch, CURLOPT_POSTFIELDS,  json_encode(array("input" => $input)));
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $result = curl_exec($ch);
    curl_close($ch);

    return json_decode($result);
}

// Query for tile Curs Banca Comerciala Feroviara
$result = query("7d00ba0e-947c-403f-b33b-886a7ee2a300", array(
    "webpage/url" => "http://www.bfer.ro/ro/curs-valutar/",
), $userGuid, $apiKey, false);

if(count($result->results) > 0) {
    foreach ($result->results as $index => $row) {
        echo($row->html_1);
        echo '<br />';
    }
} else {
    echo 'No results found';
}

?>

I just added the if(count($response->results) > 0) in case the API is returning nothing (it may happens if the page requested is unavailable).

I hope it's answering your question. Let me know if you need any help :)

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!