Help me

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • WuangLI
    Junior Member
    • Feb 2016
    • 1

    #1

    Help me

    Hi. I am building the betfair project in php.
    I consider the lots of examples in the forum, so I use some examples.
    Here are examples that I have used.

    PHP Code:
    function getACookie($username, $password){
        
        
    $loginEndpoint= "https://identitysso.betfair.com/api/login";
        
        
    $cookie = "";
        
        
    $login = "true";
        
    $redirectmethod = "POST";
        
    $product = "home.betfair.int";
        
    $url = "https://www.betfair.com/";

        
    $fields = array
            (
                
    'username' => urlencode($username),
                
    'password' => urlencode($password),
                
    'login' => urlencode($login),
                
    'redirectmethod' => urlencode($redirectmethod),
                
    'product' => urlencode($product),
                
    'url' => urlencode($url)
            );

        
    //open connection
        
    $ch = curl_init($loginEndpoint);


        
    //url-ify the data for the POST
        
    $counter = 0;
        
    $fields_string = "&";
        
        foreach(
    $fields as $key=>$value) 
            { 
                if (
    $counter > 0) 
                    {
                        
    $fields_string .= '&';
                    }
                
    $fields_string .= $key.'='.$value; 
                
    $counter++;
            }

        
    rtrim($fields_string,'&');

        
    curl_setopt($ch, CURLOPT_URL, $loginEndpoint);
        
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        
    curl_setopt($ch, CURLOPT_POST, true);
        
    curl_setopt($ch, CURLOPT_POSTFIELDS,$fields_string);
        
    curl_setopt($ch, CURLOPT_HEADER, true);  // DO  RETURN HTTP HEADERS
        
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  // DO RETURN THE CONTENTS OF THE CALL

        //execute post

        
    $result = curl_exec($ch);


    //  echo $result;

        
    if($result == false) 
            {
                    echo 
    'Curl error: ' . curl_error($ch);
            } 
        
        else 
            {
                
    $temp = explode(";", $result);
                
    $result = $temp[0];
                
                
    $end = strlen($result);
                
    $start = strpos($result, 'ssoid=');
                
    $start = $start + 6;
            
                
    $result = substr($result, $start, $end);
            }
        
    curl_close($ch);
        
        return 
    $result;
    }


    //SPORTSAPI

    function getAllEventTypes($appKey, $sessionToken)
    {
     
        
    $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listEventTypes/', '{"filter":{}}');
        
        return 
    $jsonResponse;
    }
     
    function 
    extractHorseRacingEventTypeId($allEventTypes)
    {
        foreach (
    $allEventTypes as $eventType) {
            if (
    $eventType->eventType->name == 'Horse Racing') {
                return 
    $eventType->eventType->id;
            }
        }
    }

    function 
    sportsApingRequest($appKey, $sessionToken, $operation, $params)
    {
        
    $endpoint = "https://api.betfair.com/exchange/betting/json-rpc/v1";
        
    $url = $endpoint.$operation;
        
    //echo "URL: ".$url."\r\n";
        
        
    $ch = curl_init();
        
    curl_setopt($ch, CURLOPT_URL, $url);
        
    curl_setopt($ch, CURLOPT_POST, 1);
        
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
        
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
            
    'X-Application: ' . $appKey,
            
    'X-Authentication: ' . $sessionToken,
            
    'Accept: application/json',
            
    'Content-Type: application/json'
        
    ));
         
        if(
    $params != "")
            {
                
    curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            }
     
        
    $response = json_decode(curl_exec($ch));
     
        
    $http_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        
    curl_close($ch);
     
        if (
    $http_status == 200) {
            return 
    $response;
        } else {
            echo 
    'Call to api-ng failed: ' . "\n";
           
            echo  
    'Response: ' . json_encode($response);
            
        }
    }

    function 
    getNextUkHorseRacingMarket($appKey, $sessionToken, $horseRacingEventTypeId)
    {
        
         
    //$jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listEventTypes', '{"filter":{}}');
          
    $params = '{"filter":{}}';
       
    /*
        $params = '{"filter":{"eventTypeIds":["' . $horseRacingEventTypeId . '"],
                  "marketCountries":["GB"],
                  "marketTypeCodes":["WIN"],
                  "marketStartTime":{"from":"' . date('c') . '"}},
                  "sort":"FIRST_TO_START",
                  "maxResults":"1",
                  "marketProjection":["RUNNER_DESCRIPTION"]}';
        */
        
    $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listMarketCatalogue/', $params);
        
        return 
    $jsonResponse[0]->result[0];
    } 
    And here is the call instruction that I have used.

    PHP Code:

    $allEventTypes 
    = getAllEventTypes($appKey, $sessionToken); // Get all Event Types
                            
    $horseRacingEventTypeId = extractHorseRacingEventTypeId($allEventTypes); //
                            
                                                   
    $nextHorseRacingMarket = getNextUkHorseRacingMarket($appKey, $sessionToken, $horseRacingEventTypeId); 
    But the result is not good.
    PHP Code:
    $nextHorseRacingMarket = getNextUkHorseRacingMarket($appKey, $sessionToken, $horseRacingEventTypeId); 
    The response of this function is following.

    Call to api-ng failed: Response: {"detail":{},"faultcode":"Client","faultstring":"D SC-0018"}

    why? Please help me.
    Thanks.
  • jabe
    Senior Member
    • Dec 2014
    • 705

    #2
    DSC018 and other common error codes are listed on page 257 of the manual. Help yourself to a copy if you haven't got one. Link below.

    DSC018 indicates that a mandatory parameter has been omitted.

    Which is odd, because there aren't any for ListEventTypes.

    It's been a while since I've done any PHP, alas, so I've not spotted anything wrong with what you've coded.


    PDF https://api.developer.betfair.com/se...pageId=4392320

    Comment

    • betdynamics
      Junior Member
      • Sep 2010
      • 534

      #3
      Have you actually logged in and stored the session token for the calls to the API ?
      Do you have a valid AppKey ?

      Comment

      • yuriy_6191990
        Junior Member
        • Feb 2016
        • 1

        #4
        I think you have not app key.

        Comment

        Working...
        X