Login process overview

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts

  • birchal
    replied
    Originally posted by heja View Post
    Here's a working non-interactive login code in C#:

    public bool loginBot() {
    bool loginSucceeded = false;

    try {
    const string postData = "username=yourbetfairusername&password=yourbetfair password";
    X509Certificate2 x509certificate = new X509Certificate2("client-2048.p12", "yourp12password");
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://identitysso-api.betfair.com/api/certlogin");
    request.UseDefaultCredentials = true;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Headers.Add("X-Application", "yourdeveloperappkey");
    request.ClientCertificates.Add(x509certificate);
    request.Accept = "*/*";
    request.Proxy = null;
    using (Stream stream = request.GetRequestStream()) {
    using (StreamWriter writer = new StreamWriter(stream, Encoding.Default)) {
    writer.Write(postData);
    }
    }
    using (Stream stream = ((HttpWebResponse) request.GetResponse()).GetResponseStream()) {
    using (StreamReader reader = new StreamReader(stream, Encoding.Default)) {
    var jsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<Logi nResponse>(reader.ReadToEnd());
    if (jsonResponse.loginStatus == "SUCCESS") {
    saveSession(jsonResponse.sessionToken);
    loginSucceeded = true;
    } else {
    System.Media.SystemSounds.Exclamation.Play();
    MessageBox.Show(String.Format("Betfair says:{0}{1}", Environment.NewLine, jsonResponse.loginStatus), "Login ERROR");
    }
    }
    }
    } catch (Exception ex) {
    System.Media.SystemSounds.Exclamation.Play();
    MessageBox.Show(ex.ToString(), "Login ERROR");
    }

    return loginSucceeded;
    }

    And the corresponding LoginResponse class:


    public class LoginResponse {
    [JsonProperty(PropertyName = "sessionToken")]
    public string sessionToken { get; set; }

    [JsonProperty(PropertyName = "loginStatus")]
    public string loginStatus { get; set; }
    }
    Do you have this code in DELPHI?

    Leave a comment:


  • snegst
    replied
    Hello. I'm trying to login using Non-interactive-cSharp. But every time I catch "Could not load the certificate: The network password is incorrect".
    I tried many times, but every time catch this.

    pass, wich I input is my. and its correct.
    Can you help me?

    Leave a comment:


  • SuperJag
    replied
    Originally posted by Tipmanager1 View Post
    This is C# (NET 4.5) function to write SSOID to console, use a converter tool to translate to VB.

    static async void getSSOID()
    {
    try
    {
    // Create a New HttpClient object.
    HttpClient client = new HttpClient();
    string uri = "https://identitysso.betfair.com/api/login";
    var postData = new List<KeyValuePair<string, string>>();
    postData.Add(new KeyValuePair<string, string>("username", "***"));
    postData.Add(new KeyValuePair<string, string>("password", "***"));
    postData.Add(new KeyValuePair<string, string>("login", "true"));
    postData.Add(new KeyValuePair<string, string>("redirectMethod", "POST"));
    postData.Add(new KeyValuePair<string, string>("product", "home.betfair.int"));
    postData.Add(new KeyValuePair<string, string>("url", "https://www.betfair.com/"));
    HttpContent content = new FormUrlEncodedContent(postData);

    client.BaseAddress = new Uri(uri);

    var result = await client.PostAsync(uri, content);
    string myHeaders = result.Headers.ToString();
    int myStartIndex = myHeaders.IndexOf("ssoid=")+6;
    string myString = myHeaders.Substring(myStartIndex);
    int myLength = myString.IndexOf(";");
    string ssoid = myHeaders.Substring(myStartIndex, myLength);

    Console.WriteLine(ssoid);


    }
    catch (HttpRequestException e)
    {
    Console.WriteLine("\nException Caught!");
    Console.WriteLine("Message :{0} ", e.Message);
    }
    }
    Hi Tipmanager1

    Thanks for your code. I have been trying to get HttpClient working for sometime.

    Leave a comment:


  • DannyD
    replied
    Special characters error. Please help.

    Originally posted by heja View Post
    Here's a working non-interactive login code in C#:

    public bool loginBot() {
    bool loginSucceeded = false;

    try {
    const string postData = "username=yourbetfairusername&password=yourbetfair password";
    X509Certificate2 x509certificate = new X509Certificate2("client-2048.p12", "yourp12password");
    HttpWebRequest request = (HttpWebRequest) WebRequest.Create("https://identitysso-api.betfair.com/api/certlogin");
    request.UseDefaultCredentials = true;
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.Headers.Add("X-Application", "yourdeveloperappkey");
    request.ClientCertificates.Add(x509certificate);
    request.Accept = "*/*";
    request.Proxy = null;
    using (Stream stream = request.GetRequestStream()) {
    using (StreamWriter writer = new StreamWriter(stream, Encoding.Default)) {
    writer.Write(postData);
    }
    }
    using (Stream stream = ((HttpWebResponse) request.GetResponse()).GetResponseStream()) {
    using (StreamReader reader = new StreamReader(stream, Encoding.Default)) {
    var jsonResponse = Newtonsoft.Json.JsonConvert.DeserializeObject<Logi nResponse>(reader.ReadToEnd());
    if (jsonResponse.loginStatus == "SUCCESS") {
    saveSession(jsonResponse.sessionToken);
    loginSucceeded = true;
    } else {
    System.Media.SystemSounds.Exclamation.Play();
    MessageBox.Show(String.Format("Betfair says:{0}{1}", Environment.NewLine, jsonResponse.loginStatus), "Login ERROR");
    }
    }
    }
    } catch (Exception ex) {
    System.Media.SystemSounds.Exclamation.Play();
    MessageBox.Show(ex.ToString(), "Login ERROR");
    }

    return loginSucceeded;
    }

    And the corresponding LoginResponse class:


    public class LoginResponse {
    [JsonProperty(PropertyName = "sessionToken")]
    public string sessionToken { get; set; }

    [JsonProperty(PropertyName = "loginStatus")]
    public string loginStatus { get; set; }
    }
    First I want to thank HEJA on this example, it is really working. But it is not for absolute noobs like me. It took me 3 days to make it work.

    I have question:
    -When I put Password with special characters, I get error: "INVALID_USERNAME_OR_PASSWORD" but when I change it to numbers and letters it works.
    -Can anybody help me, I am absolute beginner so be easy in explanation. I understand it has to do with encoding.

    Leave a comment:


  • Drifter
    replied
    Good call! I switched to the other key, re-ran it and it failed because of the bet size, which is set to 1.50, and therefore as expected! Thanks - not sure how long it would have taken me to realise that.

    Leave a comment:


  • Mr.Anderson
    replied
    Just guessing, but that sounds like an error you might get if you use the delayed app key?

    "The delayed App Key returns delayed price data and does not allow betting transactions to be performed (placeOrders,replaceOrders,updateOrders, cancelOrders)"

    Leave a comment:


  • Drifter
    replied
    I got most of the way there - created the certificate and verified it with curl; got the Application Key and then tried to run the Python example off Github. It runs more or less to completion, except for the placeBets function which returned this:

    "errorDetails":"INSUFFICIENT_PRIVILEGES","errorCod e":"SERVICE_BUSY","requestUUID":"prdang001-11201203-0011ee67ba"}}},"id":1}

    SERVICE_BUSY I can understand to some extent, but INSUFFICIENT_PRIVILEGES doesn't make much sense to me - is that simply because I am running against a test bed?

    Leave a comment:


  • Mr.Anderson
    replied
    That's good to know. Thanks JayBee! I will look into it next week.

    Leave a comment:


  • JayBee
    replied
    Originally posted by Mr.Anderson View Post
    Hi Vic!

    I get that error message too (except in another language) when I try to log in with Betfair's little login program (SampleAPI.exe). (I started a thread about it last week http://forum.bdp.betfair.com/showthread.php?t=2093)

    Do you still get that error if you try to log in using that program? If you don't, what was the solution, and if you do, have you been able to log in anyway using another method?
    When I use SampleAPI.exe I get the error but when I use a webrowser component in a form and point it to https://identitysso.betfair.com/view/login then the login works fine.

    If you can do likewise then avoid the .exe

    Leave a comment:


  • Mr.Anderson
    replied
    Originally posted by vic View Post
    I've decided to try the interactive way and called the login url with AppKey. Login page appears but when the webBrowser Username & Password fields are filled in and I click the Login button it comes back with "We are experiencing some technical issues and unable to proceed with your login. Please try again later". Any ideas anyone as this is getting to be a pain.
    Hi Vic!

    I get that error message too (except in another language) when I try to log in with Betfair's little login program (SampleAPI.exe). (I started a thread about it last week http://forum.bdp.betfair.com/showthread.php?t=2093)

    Do you still get that error if you try to log in using that program? If you don't, what was the solution, and if you do, have you been able to log in anyway using another method?

    Leave a comment:


  • Mr.Anderson
    replied
    Originally posted by gus View Post
    You don't send the appKey to login, (tho you do for keepAlive and logOut).
    I just read the descriptions for the keepalive and logout operations, and they say that sending the appkey is optional? Is that something which has changed recently? Can you get by without using your appkey at all? Or have I misunderstood something (quite likely )?

    Leave a comment:


  • Corvus
    replied
    I'm still really struggling with login

    I'm struggling quite a bit because HTTP and JSON-RPC are both new to me.

    I've tried to use the interactive login examples given in this thread so far, and got the following in VB.net (4.0):

    Code:
    Public Function Test2() As String
            ' Create a request using a URL that can receive a post. 
            Dim request As WebRequest = WebRequest.Create("https://identitysso.betfair.com/api/login")
            ' Set the Method property of the request to POST.
            request.Method = "POST"
            ' Create POST data and convert it to a byte array.
            Dim postData As String = "username=username&password=password&login=true&redirectMethod=POST&product=home.betfair.int&url=https://www.betfair.com/"
            Dim byteArray As Byte() = Encoding.UTF8.GetBytes(postData)
            ' Add appkey
            request.Headers.Add("X-Application", LiveAppKey)
            ' Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length
            Try
                ' Get the request stream.
                Dim dataStream As Stream = request.GetRequestStream()
                ' Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length)
                ' Close the Stream object.
                dataStream.Close()
                ' Get the response.
                Dim response As WebResponse = request.GetResponse()
                'Get the header from the response.
                Dim responseFromServer As String = response.Headers.ToString
                ' Clean up the streams.
                response.Close()
                ' Return the info to be displayed
                Return CType(response, HttpWebResponse).StatusDescription & vbCrLf & "------" & vbCrLf & responseFromServer
            Catch ex As Exception
                Return ex.Message
            End Try
        End Function
    And I just get this as the output, I blanked out a couple of numbers because I don't know if they are sensitive or not. But I can't see any ssoid info in the header and don't know where I'm going wrong.

    Obviously I put my real username and password in the code above (and the appkey is defined as a constant elsewhere) although this doesn't actually make any difference!

    I'm sure I'm doing something really basic wrong, but I don't really understand what I'm supposed to be doing yet . Any tips would be greatly appreaciated.

    Code:
    OK
    ------
    Set-Cookie: wsid=cxxxxxx-4895-11e3-880d-xxxxxxxxx; Domain=.betfair.com; Expires=Fri, 08-Nov-2013 17:19:48 GMT; Path=/,vid=cxxxxxx-4895-11e3-880d-xxxxxxx;
    Domain=.betfair.com; Expires=Mon, 06-Nov-2023 16:49:48 GMT; Path=/
    Cache-Control: no-cache,must-revalidate,no-store
    Expires: -1
    pragma: no-cache
    X-FRAME-OPTIONS: DENY
    Content-Type: text/html;charset=UTF-8
    Content-Language: en-GB
    Transfer-Encoding: chunked
    Date: Fri, 08 Nov 2013 16:49:48 GMT

    Leave a comment:


  • SuccessfulLoser
    replied
    PHP Example

    For anyone wishing to establish a non-interactive session using PHP...
    PHP Code:
    $ch curl_init();
            
    curl_setopt($chCURLOPT_URL'https://identitysso-strongauth.betfair.com/api/certlogin');
    curl_setopt($chCURLOPT_POST1);
    curl_setopt($chCURLOPT_SSLCERTdirname(__FILE__)."/client-2048.crt");
    curl_setopt($chCURLOPT_SSLKEYdirname(__FILE__)."/client-2048.key");
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
    curl_setopt($chCURLOPT_HTTPHEADER, array(
                                                       
    'X-Application: ' MY_APP_KEY,
                                                       
    'Content-Type: application/x-www-form-urlencoded'
                                                       
    ));
            
    $postData 'username=MY_USERNAME&password=MY_PASSWORD';    
    curl_setopt($chCURLOPT_POSTFIELDS$postData);
            
    $response json_decode(curl_exec($ch));
            
    curl_close($ch); 

    Leave a comment:


  • rendalli
    replied
    Not able to generate AppKeys

    Still not able to generate Appkeys.

    I open https://api-ng.betstores.com/account/ - I am logged in and still I have that "Session Token"-Field to fill in. What am I supposed to put in this ssoid-Field?

    Tried Firefox, Chrome etc.

    Edit: Ok worked out finally. I had to look into the Cookie to get the ssoid. I thought this would only be necessary if I wanted to automate interactive login as AlgoTrader described.
    Last edited by rendalli; 24-10-2013, 12:03 AM.

    Leave a comment:


  • BetfairDeveloperProgram
    replied
    New JSON interface -Keep Alive and Logout methods

    Hi,

    Due to the initial problem with the implementation of the Keep Alive and Logout methods, the interface for these operations has now been updated.

    Please see the updated JSON Keep Alive and Logout methods via https://api.developer.betfair.com/se...28bot%29+login


    Thanks

    Neil

    Leave a comment:

Working...
X