VB.Net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • TheDruid
    Junior Member
    • Aug 2009
    • 2

    #1

    VB.Net

    I've seen a few requests from people stuck trying to use the new API with VB.net.
    I've been messing around with it for a couple of weeks now, and I just feel like I'm starting to make some progress.

    There are a few VB-specific 'gotchas' that had me stuck...

    None of my code is particularly great, and it's just a bunch of routines right now, rather than an application, but I'm happy to post some snippets if anyone's interested?
    (might save someone some time)
  • davecon
    Junior Member
    • Dec 2010
    • 86

    #2
    Hi that would be brilliant
    I had a quick look myself and did not pursue due to the fact we may have to pay (Seems ok for a few more months now)
    I never got to the be able to Log In and the Excel thingy didn't work
    Any sort of Basic example would be very much appreciated
    Log in and Show my Balance would be cool
    Cheers for your post (This thread maybe better in NET section if you dont mind me saying)
    Thanks again
    Dave

    Comment

    • Lopiner
      Junior Member
      • Feb 2009
      • 117

      #3
      Thanks TheDruid, it would be greatly appreciated.

      Just a question, are you building response objects for every request and then using JSON.net to dump the response in the objects?

      ty
      fooledbyabet.com

      Comment

      • Hannible Lector
        Junior Member
        • Sep 2013
        • 2

        #4
        TheDruid any working example would be appreciated.

        Comment

        • davecon
          Junior Member
          • Dec 2010
          • 86

          #5
          Hi Druid
          Are we waiting for the Winter Solstice lol
          Just how to log in will do and will be greatly appreciated
          We can sort the rest between us surely
          Cheers
          Dave


          Originally posted by TheDruid View Post
          I've seen a few requests from people stuck trying to use the new API with VB.net.
          I've been messing around with it for a couple of weeks now, and I just feel like I'm starting to make some progress.

          There are a few VB-specific 'gotchas' that had me stuck...

          None of my code is particularly great, and it's just a bunch of routines right now, rather than an application, but I'm happy to post some snippets if anyone's interested?
          (might save someone some time)

          Comment

          • muggles
            Junior Member
            • Oct 2013
            • 1

            #6
            Originally posted by davecon View Post
            Hi Druid
            Are we waiting for the Winter Solstice lol
            Just how to log in will do and will be greatly appreciated
            We can sort the rest between us surely
            Cheers
            Dave
            Hi Dave

            I've been having problems getting started with the new API, but I can at least help with the login.

            I'm using Visual Studio Express 2013 for Windows

            1. Create a new windows forms application (File>New Project>Windows Forms Application)

            I called mine API_NG_EXAMPLE

            2. You will need to increase the size of Form1 to accomodate the controls you will be using.

            3. Add a webBrowser (Webbrowser1 in my code). Set Visible to True, ScriptErrorsSuppressed to False.

            4. Add a login Button (BtnLogin in my code).

            5. Add a label to display the sessiontoken when acquired (Lblsessiontoken).

            The code is below - it's quick and dirty but will get you a session token. You will as a minimum need to edit the Appkey declaration to use your own application key.

            Code:
            Public Class Form1
                ' Your App key
                Public Appkey As String = "<your app key goes here>"
                Public sessiontoken As String = "Not Logged In"
                Public loginurl As String = "https://identitysso.betfair.com/view/login?product=" & Appkey & "&url=https://www.betfair.com"
            
                Private Sub Btnlogin_Click(sender As Object, e As EventArgs) Handles Btnlogin.Click
                    WebBrowser1.Select()
                    WebBrowser1.Visible = True
                    WebBrowser1.Navigate(loginurl)
                End Sub
            
                Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
                    ' On embedded web browser response get cookie
                    Dim cookies As String = Me.WebBrowser1.Document.Cookie
                    'check that we are not already logged in
                    If sessiontoken = "Not Logged In" Then
                        If cookies IsNot Nothing Then
                            ' successful login will return session token
                            Dim ind As Integer = cookies.IndexOf("ssoid=")
                            If ind > 0 Then
                                ' we have session token
                                Dim tmp As String = cookies.Substring(ind + "ssoid".Length)
                                sessiontoken = tmp.Substring(0, tmp.IndexOf(";"))
                                Lblsessiontoken.Text = sessiontoken
                                WebBrowser1.Visible = False
                                ' need to start keepalive timer here!
                            End If
                        End If
                    End If
                End Sub
            End Class
            No apologies for poor style in the code - and I'm sure there is a better way of extracting the sessiontoken from the cookie, but I have tried to make the method easy to follow.
            I hope this helps,

            Paul

            Comment

            Working...
            X