Anyone please help...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cks1007
    Junior Member
    • Mar 2020
    • 9

    #1

    Anyone please help...

    following is my php code , but I can not see any result.


    index.php
    PHP Code:
    <html>
    <head>
    <title>Betfair</title>
    </head>
    <body>

    <?php
    require "api.php";

    $appKey"my app key";
    $sessionToken="my session";

    echo 
    getAllEventTypes($appKey$sessionToken);
    ?>

    api.php
    PHP Code:
    <?

    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":{}}');
    return $jsonResponse[0]->result;
    }

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

    ?>
    Last edited by cks1007; 10-03-2020, 02:49 AM.
  • geoffw123
    Senior Member
    • Mar 2014
    • 250

    #2
    Hi You are much more likely to get someone to help you if you post the JSON string you are sending to Betfair, and the JSON string you are getting back.

    Comment

    • cks1007
      Junior Member
      • Mar 2020
      • 9

      #3
      dear geoffw123
      Thanks for your reply.
      I just use index.php and api.php
      and get not get any JSON strin from Betfair API server.
      DO I miss any thing?

      Comment

      • geoffw123
        Senior Member
        • Mar 2014
        • 250

        #4
        Hi

        For your php code to work properly, it needs to construct a data request string that it sends to the Betfair Server, the Server will reply with a different JSON string. Your php code needs to then decode this Json response to give you the data you requested. (Your code has json_encode and json_decode to do these functions)

        To make progress on this you need to look at these Json strings. Two options here

        1) Put some debug code in your PHP App, to print these out.

        or

        2) Download a comms monitor tool such as Fiddler which you can use to inspect the json data flowing in and out of your App

        Option 2 is preferred as you can then be 100% sure what data is going out on the wires.

        Regards
        Last edited by geoffw123; 10-03-2020, 10:23 PM.

        Comment

        • cks1007
          Junior Member
          • Mar 2020
          • 9

          #5
          Dera geoffw123

          Do you have any workable sample for my reference?
          Maybe help me to get listEventTypes output is enough.
          Thanks again..

          Comment

          • geoffw123
            Senior Member
            • Mar 2014
            • 250

            #6
            Hi

            I just used the Betfair examples to get mine working, I used C# example though, sorry I dont know PHP.

            You could also try using the Betfair Visualiser, that is a handy web tool to let you inspect working JSON data and compare to your Json data.

            https://docs.developer.betfair.com/v...ts-operations/
            Last edited by geoffw123; 11-03-2020, 09:38 AM.

            Comment

            • cks1007
              Junior Member
              • Mar 2020
              • 9

              #7
              hi geoffw123

              thanks for your reply. I find the bug and already fix the problem.

              But new problem happens as

              [{"jsonrpc":"2.0","error":{"code":-32602,"message":"DSC-0018"},"id":1}]



              Originally posted by geoffw123 View Post
              Hi

              I just used the Betfair examples to get mine working, I used C# example though, sorry I dont know PHP.

              You could also try using the Betfair Visualiser, that is a handy web tool to let you inspect working JSON data and compare to your Json data.

              https://docs.developer.betfair.com/v...ts-operations/

              Comment

              • denimen9
                Junior Member
                • Feb 2019
                • 7

                #8
                Hi geoffw132,

                From my experience Betfair doesnt change the sport ID's that much so again you should just hardcode them from the Betfair Visualiser to save the number of requests you make. I also suggest using Postman+Betfair Visualiser for easier debug and to get more knowledge about Betfair api itself, but lets get back to your issue:

                PHP Code:
                $curl curl_init();
                curl_setopt_array($curl, array(
                  
                CURLOPT_URL => "https://api.betfair.com/exchange/betting/json-rpc/v1",
                  
                CURLOPT_RETURNTRANSFER => true,
                  
                CURLOPT_ENCODING => "",
                  
                CURLOPT_MAXREDIRS => 10,
                  
                CURLOPT_TIMEOUT => 5,
                  
                CURLOPT_FOLLOWLOCATION => true,
                  
                CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                  
                CURLOPT_CUSTOMREQUEST => "POST",
                  
                CURLOPT_POSTFIELDS =>"[{"jsonrpc": "2.0", "method": "SportsAPING/v1.0/listEventTypes", "params": {"filter":{}}, "id": 1}]",
                  
                CURLOPT_HTTPHEADER => array(
                    
                "X-Application:  YOURAPIKEY",
                    
                "X-Authentication:  SESSIONTOKEN",
                    
                "Accept:  application/json",
                    
                "Content-Type: application/x-www-form-urlencoded"
                  
                ),
                ));

                $response curl_exec($curl);
                curl_close($curl);
                echo 
                $response
                Considering you made a successful login request, this should do it for you. If you need a more detailed explanation of Visualiser+Postman usage to make most out of the api, just msg and I will write you a tut for it.

                Comment

                Working...
                X