Betfair Developers


Delphi
Discussions about Delphi development(pronounced DEHL-FAI). Delphi from Borland competes with Visual Basic as an offering for an object-oriented, visual programming approach to application development.

Post Reply
Happy Harry1 Happy Harry1 is offline
Junior Member
 
Default Help with Paradox Login

Hi there. This is probably the only place that will have any knowledge of Borland long dead languages.

I am finding it impossible to login and yet it should be possible.

Here is the code that I am using but all I get returned is the entire script for the entire Betfair Pages. Any help or ideas would be gratefully appreciated and I have tried all sorts of alternatives. The strings in the Variables are not currently being used but will be later on and it processes ok but wont log me in.

method pushButton(Var eventInfo Event)

var
oaXMLHTTP oleAuto
encodedAuth,
APIKey,
APIpwd string
endvar

RequestURL = "https://identitysso.betfair.com/api/login"
resultXMLstr2 = ""
err1 = ""
isOK = false


msgStr="?username=xxxxxxxxx&password=xxxxxxxxxx" ; note xxxxxxxxx&xxxxxxxx - my username&password

try
whichStep = "msXML Open"
if oaXMLHTTP.open("Msxml2.XMLHTTP.3.0") then
whichStep = "HTTP Open"
oaXMLHTTP^open("POST",RequestURL, false)
whichStep = "Set Request Header"
oaXMLHTTP^setRequestHeader("Accept: application/json", "X-Application: <valid application string>")
whichStep = "Send Data"
oaXMLHTTP^send(msgStr) ; sync so it'll wait
resultXMLstr2 = oaXMLHTTP^responseText
isOK = true
endif
onFail
endTry
if not isOK then
errorShow(whichStep)
return
endif

resultXMLstr2.view("Returned") ; have to decode result from JSON

endMethod


Many thanks for any thoughts.
bnl bnl is offline
Senior Member
 
Default

Hi!


What is returned in resultXMLstr2 ?

what does onFail do ? it seem misplaced in my eyes,
(Yes, I do not know Paradox, but still)

/Björn
Happy Harry1 Happy Harry1 is offline
Junior Member
 
Default

Here is the top of the return. There is a lot more of it.








<!DOCTYPE html>
<!--[if IE 8]>
<html class="ie8" lang="en-GB"><![endif]--><!--[if IE 7]>
<html class="ie7" lang="en-GB"><![endif]--><!--[if lt IE 7]>
<html class="ie6" lang="en-GB"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!-->
<html lang="en-GB">
<!--<![endif]-->
<head>

<meta name="format-detection" content="telephone=no">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge" >

<title>
Betfair: Log in </title>
<link rel="shortcut icon" href="//identitysso.cdnbf.net/favicon_3485_.ico"/>
<link href="//ssc.cdnbf.net/static/all-8513092a18f38e1045773050ac4f760b.css" type="text/css" rel="stylesheet">

<link href="//identitysso.cdnbf.net/resources/bundles/yui_dialog_footer-desktop_module-info_platformapi_moduleapi_module_footer_header_lo gin/all_3485_.css" type="text/css" rel="stylesheet">

</head>
<body class="sso-content sso-no-js layout-page jur-international AU ">
<!-- Google Tag Manager -->
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-P32JX6"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:''; j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-P32JX6');
</script>
<!-- End Google Tag Manager -->
<script type="text/javascript">
document.body.className = document.body.className.replace("sso-no-js","");
var sso = window.sso || {};
</script>
<div id="content-login">
<div id="header-placeholder">
<div class="centralWrapper">


<div id="mod-header-7541-container" class="mod">



<div id="mod-header-7541" class="mod-header mod-header-header">
<a href="" class="homeLink" style="visibility:hidden;"><span><span></a>

<div class="header-image ">
</div>

</div>
</div>
</div>
</div>

<div class="centralWrapper contentShadow" >
<div id="main-wrapper" class="main-wrapper">
<div id="main" class="main">


<di
bnl bnl is offline
Senior Member
 
Default

does not look correct.


I use this code to log in. (Ada) but you should get it anyaway.
I see that you do not set form-url-encoded....


Code:
  procedure Login is
    Login_HTTP_Headers : Aws.Headers.List := Aws.Headers.Empty_List;
    AWS_Reply    : Aws.Response.Data;
    Header : AWS.Headers.List;
  begin
    Aws.Headers.Set.Add (Login_HTTP_Headers, "User-Agent", "AWS-BNL/1.0");

    declare
      Data : String :=  "username=" & Global_Token.Get_Username & "&" &
                         "password=" & Global_Token.Get_Password &"&" &
                         "login=true" & "&" &
                         "redirectMethod=POST" & "&" &
                         "product=home.betfair.int" & "&" &
                         "product=home.betfair.int" & "&" &
                         "url=https://www.betfair.com/";
    begin
      AWS_Reply := Aws.Client.Post (Url          => "https://identitysso.betfair.com/api/login",
                                    Data         => Data,
                                    Content_Type => "application/x-www-form-urlencoded",
                                    Headers      => Login_HTTP_Headers,
                                    Timeouts     => Aws.Client.Timeouts (Each => 30.0));
    end ;
    Log(Me & "Login", "reply" & Aws.Response.Message_Body(AWS_Reply));
    
    -- login reply should look something like below (522 chars)
    -- <html>
    -- <head>
    --     <title>Login</title>
    -- </head>
    -- <body onload="document.postLogin.submit()">
    -- <iframe src="https://secure.img-cdn.mediaplex.com/0/16689/universal.html?page_name=loggedin&amp;loggedin=1&amp;mpuid=6081705" HEIGHT="1" WIDTH="1" FRAMEBORDER="0" ></iframe>
    -- <form name="postLogin" action="https://www.betfair.com/" method="POST">
    --     <input type="hidden" name="productToken" value="UeJjgdrftgyhujikolleerrtythyDhsrHQkOvHu7alH5NCldA="/>
    --     <input type="hidden" name="loginStatus" value="SUCCESS"/>
    -- </form>
    -- </body>
    -- </html>
    
    declare
      String_Reply : String := Aws.Response.Message_Body(AWS_Reply);
    begin  
      if String_Reply'length < 500 then
        raise Login_Failed with "Bad reply from server at login";
      end if;
    end ;
    
    Header := AWS.Response.Header(AWS_Reply);

    for i in 1 .. AWS.Headers.Length(Header) loop
      declare
        Head : String := AWS.Headers.Get_Line(Header,i);
        Index_First_Equal : Integer := 0;
        Index_First_Semi_Colon : Integer := 0;
        -- Set-Cookie: ssoid=o60xdrtyujhfdssaasddfger6fycB2Dw7eHLiWoA1vI=; Domain=.betfair.com; Path=/
      begin
        if Position(Head,"ssoid") > Integer(0) then
          Log("Login"," " & Head);
          for i in Head'range loop
            case Head(i) is
              when '=' =>
                if Index_First_Equal = 0 then
                  Index_First_Equal := i;
                end if;

              when ';' =>
                if Index_First_Semi_Colon = 0 then
                  Index_First_Semi_Colon := i;
                end if;
              when others => null;
            end case;
          end loop;
          if Index_First_Equal > Integer(0) and then Index_First_Semi_Colon > Index_First_Equal then
            Log("Login","ssoid: '" & Head(Index_First_Equal +1 .. Index_First_Semi_Colon -1) & "'");
            Global_Token.Set(Head(Index_First_Equal +1 .. Index_First_Semi_Colon -1));
          end if;
        end if;
      end;
    end loop;
  end Login;



the actual loginpage will look something like the comment in the code above.
and no, the ssoid above are not valid

/Björn
Happy Harry1 Happy Harry1 is offline
Junior Member
 
Default Getting Close. Tantalisingly close

The code now reads:-

================================================== ==============

method pushButton(Var eventInfo Event)

var
oaXMLHTTP oleAuto
encodedAuth,
APIKey,
APIpwd string
endvar

RequestURL = "https://identitysso.betfair.com/api/login"
resultXMLstr2 = ""
err1 = ""
isOK = false


msgStr="username=xxxxxxxxxx&password=xxxxxxxxxx" ; note xxxxxxxxx - my current password

try
whichStep = "msXML Open"
if oaXMLHTTP.open("Msxml2.XMLHTTP.3.0") then
whichStep = "HTTP Open"
oaXMLHTTP^open("POST",RequestURL, false)
whichStep = "Set Request Header"
oaXMLHTTP^setRequestHeader("Accept", "application/json")
oaXMLHTTP^setRequestHeader("X-Application","<Same App key from the Api Accounts Developer tool with no odd characters in it>")
whichStep = "Send Data"
oaXMLHTTP^send(msgStr) ; sync so it'll wait
resultXMLstr2 = oaXMLHTTP^responseText
isOK = true
endif
onFail
endTry
if not isOK then
errorShow(whichStep)
return
endif

resultXMLstr2.view("Returned") ; have to decode result from JSON

endMethod

================================================== ==============


And what comes back is:-

{"token":"","product":"<Same App key from the Api Accounts Developer tool with no odd characters in it>","status":"FAIL","error":"INPUT_VALIDATION_ERR OR"}

I have tried all sorts of variations of the string but it doesn't seem to process my username and password properly. Its close. Very very close.
betdynamics betdynamics is offline
Senior Member
 
Default

If your username or password contains symbols (rather than just standard alphanumerics), then you will need to ensure that they are encoded before being passed to the web page.

Take a look at https://en.wikipedia.org/wiki/Percent-encoding
bnl bnl is offline
Senior Member
 
Default

I still think you need to encode your data (user/pwd),
and tell Betfair that you are doing so.

You tell Betfair by including a http-header
"Content_Type : application/x-www-form-urlencoded"

How you actually do the encoding in Paradox - I have no idea.
Worse case scenario is to find the definition, and implement it yourself

/Björn
Happy Harry1 Happy Harry1 is offline
Junior Member
 
Default Solved

Finally cracked this and getting a session token back so now have access. The Code to do it, might help someone else is:-

================================================== ===============

var
oaXMLHTTP oleAuto
RequestURL, msgStr, resultXMLstr2 string
endvar

RequestURL = "https://identitysso.betfair.com/api/login?username=XXXXXXXXXXX&password=XXXXXXXXXXX"
resultXMLstr2 = ""
err1 = ""
isOK = false

msgStr =""

try
whichStep = "msXML Open"
if oaXMLHTTP.open("Msxml2.XMLHTTP.3.0") then
whichStep = "HTTP Open"
oaXMLHTTP^open("POST",RequestURL, false)
whichStep = "Set Request Header"
oaXMLHTTP^setRequestHeader("Accept", "application/json")
oaXMLHTTP^setRequestHeader("X-Application","YYYYYYYYYYYYY")
whichStep = "Send Data"
oaXMLHTTP^send(msgStr) ; sync so it'll wait
resultXMLstr2 = oaXMLHTTP^responseText
isOK = true
endif
onFail
endTry
if not isOK then
errorShow(whichStep)
return
endif

resultXMLstr2.view("Returned") ; have to decode result from JSON
Post Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump