1

我是使用 PHP 代码使用 Betfair api 的初学者。已经尝试了很多次。包括Dcro,Peter已经尝试了很多次。包括 Dcro、PeterColes、API-NG 示例。但从不工作。我看不到 API 服务器的任何响应。也没有任何错误代码。有高手知道为什么吗?请帮忙。非常感谢。

索引.php

<html><head><title>Betfair</title></head><body>

<?php

$appKey= "my appkey";
$username="my username";
$password="my password";
$sessionToken="my sessiontoken";

require "api.php";

echo getAllEventTypes($appKey, $sessionToken);
?>

api.php

<?

function sportsApingRequest($appKey, $sessionToken, $operation, $params)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.betfair.com/exchange/betting/json-rpc/v1");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:',
        'X-Application: ' . $appKey,
        'X-Authentication: ' . $sessionToken,
        'Accept: application/json',
        'Content-Type: application/json'
    ));

    $postData =
        '[{ "jsonrpc": "2.0", "method": "SportsAPING/v1.0/' . $operation . '", "params" :' . $params . ', "id": 1}]';


    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);

    $response = json_decode(curl_exec($ch));
    curl_close($ch);

    if (isset($response[0]->error)) {
        echo 'Call to api-ng failed: ' . "\n";
        echo  'Response: ' . json_encode($response);
        exit(-1);
    } else {
        return $response;
    }

}

function getAllEventTypes($appKey, $sessionToken)
{
    $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listEventTypes', '{"filter":{}}');
    print_r($jsonResponse);
    return $jsonResponse[0]->result;
}

function extractHorseRacingEventTypeId($allEventTypes)
{
    foreach ($allEventTypes as $eventType) {
        if ($eventType->eventType->name == 'Horse Racing') {
            return $eventType->eventType->id;
        }
    }
}

?>
4

0 回答 0