通过 curl 在 php 网页上显示 API - 只是想不通

Displaying an API via curl onto a php webpage - Just cant figure it out

所以我正在尝试使用 curl 通过 API 将网站上的信息显示到我的网站上。

而且我根本不了解 curl :(

这就是我必须从源网站获取的信息:

curl -H "IHOSTMN-API-KEY:YourIhostmnApiKeyHere" -X GET "https://ihostmn.com/api/v1/sharing/user/list_all_deposits"

它应该给出这样的响应:

{
    "result": {
        "deposits": [
            {
                "deposit_id": 36,
                "share_id": 2,
                "current_amount": 53.077553,
                "total_deposited": 24.91567,
                "total_earned": 28.146885,
                "withdraw_address": "GcUgnY5fFwTv9ef8rsggdxbdQzLEUxpp4c",
                "deposit_address": "GfUgnY5sFwTf9ez8rovtdxdEQzLcbxpb4c"
            },
            {
                "deposit_id": 37,
                "share_id": 5,
                "current_amount": 885.9591,
                "total_deposited": 521.92,
                "total_earned": 472.30566,
                "withdraw_address": "gHWHPs21H8UsSNcbfWxvn5XssAxFkcuZYe",
                "deposit_address": "g4sbWWtD3tf16Dsd8wiaJkar3zhJ82qNKP"
            },
            {
                "deposit_id": 38,
                "share_id": 6,
                "current_amount": 754.5115,
                "total_deposited": 548.52997,
                "total_earned": 416.25214,
                "withdraw_address": "LLqWFFJkNSog6VwsbPWEWE4KcXJrzB6t1K",
                "deposit_address": "LW5Vbt1gEkvVQzfVcpLmidLPpcED1Yp3yu"
            }
        ]
    },
    "error": ""
}

我已经创建了我的 php 网页,但无法正常工作,这是我写的:

curl -H "IHOSTMN-API-KEY:xxxxxxxxxxxxxxxxxxxxxxxxx" -X GET "https://ihostmn.com/api/v1/sharing/user/list_all_deposits"

$obj = json_decode($result);
echo $obj[0]->deposits;

希望你们中的一位能够为我指明正确的方向,如果可以的话,感谢您花时间提供帮助。

马克

尝试这样的事情

<?
$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'https://ihostmn.com/api/v1/sharing/user/list_all_deposits');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');


$headers = array();
$headers[] = 'Ihostmn-Api-Key: YourIhostmnApiKeyHere';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
$obj = json_decode($result);

print_r($obj->result->deposits);

if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}

curl_close($ch);

你对数组使用 [],对对象使用箭头。

我无法测试 API 但这应该可以让您抢先一步。

有用的链接:cURL