PHP Betfair Free Access API,如何构建APIRequestHeader&叫任何方法?

时间:2013-11-09 08:43:59

标签: php api soap betfair

我正在尝试编写一个简单的PHP客户端,通过免费访问API http://bdp.betfair.com/?option=com_content&task=view&id=33&Itemid=62

Betfair 获取一些数据

我可以登录&以这种方式获取会话令牌

$wsdl = 'https://api.betfair.com/global/v3/BFGlobalService.wsdl';
$soapClient = new SoapClient($wsdl); 
try {
    $ap_param = array(
        'request' => 
            array(
                'username' => 'my_username',
                'password' => 'my_password',
                'productId' => '82',    
                'ipAddress' => '',
                'locationId' => '',
                'vendorSoftwareId' => '',
            ),
        );  
    $response = $soapClient->__call("login", array($ap_param));
...

$ response是一个包含sessionToken参数的对象

但经过多次尝试后,我担心我发送的APIRequestHeader参数(http://bdp.betfair.com/docs/)格式错误,导致对任何调用的响应(例如getAllEventTypes)始终返回相同的内容:NO_SESSION

一试......

$ap_param = array(
    'request' => 
        array(
            'header' => array(
                'session_token' => $response->Result->header->sessionToken,
                'clientStamp' => 0,
            ),          
        ),
    );      

另一次尝试......

$ap_param = array(
    'request' => 
        array(
            'session_token' => $response->Result->header->sessionToken,
            'clientStamp' => 0,
        ),
    ); 

还有很多其他尝试......但

$response = $soapClient->__call("getAllEventTypes", array($ap_param));

$ response总是一样

stdClass Object
(
    [Result] => stdClass Object
        (
            [header] => stdClass Object
                (
                    [errorCode] => NO_SESSION
                    [minorErrorCode] => 
                    [sessionToken] => 
                    [timestamp] => 2013-11-09T08:41:01.015Z
                )

            [eventTypeItems] => 
            [minorErrorCode] => 
            [errorCode] => API_ERROR
        )

)

这里有人面临同样的问题吗?

1 个答案:

答案 0 :(得分:0)

那里的愚蠢错误......

session_token 应为 sessionToken

$ap_param = array(
    'request' => 
        array(
            'header' => array(
                'sessionToken' => $response->Result->header->sessionToken,
                'clientStamp' => 0,
            ),          
        ),
    );