Login process overview

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts
  • uncletone1
    Junior Member
    • Oct 2012
    • 24

    #31
    Originally posted by AlgoTrader View Post
    Curl is not a markup language. It is HTTP request testing tool. Before programming any request in any language, it is usually good idea to make it working with curl. You browser is not very good to send post requests with manually prepared data, that's the area where curl shines

    After curl proto work, just do the same in programminbg language. It usually much easier to implement that you know for sure it works, which headers/cookies to send and what server returns.
    Thanks Algo.
    I'll give Curl a go. Is there a tool that of preference for this.

    Comment

    • vic
      Junior Member
      • May 2009
      • 33

      #32
      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.

      Comment

      • gus
        Senior Member
        • Jan 2009
        • 134

        #33
        You don't send the appKey to login, (tho you do for keepAlive and logOut).

        In fact I wouldn't bother with trying to show the BFLogin page. I just send my credentials (via https POST) direct to the logon URL. Unfortuanatley i din't have C# code for my login method, but here's my Java class for login, keepAlive and logout, which may help:

        Code:
        package com.XXX.XXXX;
        
        import java.net.*;
        import java.io.*;
        import javax.net.ssl.HttpsURLConnection;
        
        
        public class Authentication
        	{
        		private static String loginTarget = "https://identitysso.betfair.com/api/login";
        		private static String keepAliveTarget = "https://identitysso.betfair.com/api/keepAlive";
        		private static String logoutTarget = "https://identitysso.betfair.com/api/logout";
        		
        		
        		public Authentication()
        			{
        				;
        			}
        			
        		public static String login(String username, String password)
        			{
        				String token = "PROBLEM";
        				
        				String s = "";
        				
        				try
        					{
        						s = "&username=" + URLEncoder.encode(username, "UTF-8");
        						s+= "&password=" + URLEncoder.encode(password, "UTF-8");
        						s+= "&login=" + URLEncoder.encode("true", "UTF-8");
        						s+= "&redirectMethod=" + URLEncoder.encode("POST", "UTF-8");
        						s+= "&product=" + URLEncoder.encode("home.betfair.int", "UTF-8");
        						s+= "&url=" + URLEncoder.encode("https://www.betfair.com/", "UTF-8");
        					}
        				catch(Exception ex)
        					{
        						ex.printStackTrace();
        					} 
        				
        				if(!s.equals(""))
        					token = makeCall(0, loginTarget, s);
        				
        				return token;
        			}
        			
        		public static String keepAlive()
        			{
        				String token = "PROBLEM";
        				String s = "";
        				
        				try
        					{
        						s = "&" + "product=" + URLEncoder.encode(YOUR_APPKEY, "UTF-8");
        						s+= "&url=" + URLEncoder.encode("https://www.betfair.com/", "UTF-8");
        					}
        					
        				catch(Exception ex)
        					{
        						ex.printStackTrace();
        					} 
        					
        				if(!s.equals(""))
        					token = makeCall(1, keepAliveTarget, s);
        				
        				return token;
        			}
        			
        		public static String logout()
        			{
        				String token = "PROBLEM";
        				String s = "";
        				
        				try
        					{
        						s = "&" + "product=" + URLEncoder.encode(YOUR_APPKEY, "UTF-8");
        						s+= "&url=" + URLEncoder.encode("https://www.betfair.com/", "UTF-8");
        					}
        					
        				catch(Exception ex)
        					{
        						ex.printStackTrace();
        					} 
        					
        				if(!s.equals(""))
        					token = makeCall(2, logoutTarget, s);
        				
        				return token;
        			}
        			
        		private static String makeCall(int call, String target, String query)
        			{
        				URL url = null;
        				HttpsURLConnection conn = null;
        				DataOutputStream outStream = null;
        				String outString = "PROBLEM";
        				
        				try
        					{
        						url = new URL(target);
        						conn = (HttpsURLConnection)url.openConnection();
        						
        						conn.setRequestMethod("POST");
        						conn.setDoOutput(true);
        						conn.setDoInput(true);
        						conn.setFollowRedirects( true );
        						
        						if(conn != null)
        							{
        								outStream = new DataOutputStream(conn.getOutputStream());
        						
        								outStream.writeBytes(query);
        								outStream.flush();
        								outStream.close();
        								conn.disconnect();
        						 
        								int responseCode = conn.getResponseCode();
        						
        								if(call == 0)
        									{
        										if(responseCode == 200)
        											{
        												String headerName = null;
        						 		
        												for (int i = 1; (headerName = conn.getHeaderFieldKey(i))!=null; i++) 
        													{
        														if (headerName.equals("Set-Cookie")) 
        															{                  
        																String cookie = conn.getHeaderField(i);
        														
        																if(cookie.indexOf("ssoid") > -1)
        																	outString = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
        															}
        													}
        											}
        									}
        						 	
        								else if(responseCode == 200)
        									outString = "" + responseCode;
        							}//if(conn != null)
        					}
        					
        				catch(Exception ex)
        					{
        						ex.printStackTrace();
        					}
        					
        				return outString;
        			}
        	}
        Last edited by gus; 23-08-2013, 09:47 AM.

        Comment

        • vic
          Junior Member
          • May 2009
          • 33

          #34
          Thanks Gus
          that's quite helpful.

          Comment

          • MiloRambaldi
            Junior Member
            • Sep 2013
            • 3

            #35
            Originally posted by uncletone1 View Post
            Right. I have got the interactive option working as per the instructions for C#

            https://api.developer.betfair.com/se...op+Application
            I tried the SampleAPI C# project from the Interactive-cSharp folder of the git repo, but stuff seems to be missing: It does not compile, and there is no Logon button object or txtAppKey object in the form.

            Anyone else noticed this?

            Comment

            • vic
              Junior Member
              • May 2009
              • 33

              #36
              Yea Milo, as I've said elsewhere c# example doesn't work for me. There's gaps to be filled in that only professionals could do. What we really need for us part-timers is a step by step guide, the sort that you get with API6, to get something that works. Then we can all diversify as individuals and add little snippets to the forum.

              Comment

              • Let it Ride
                Junior Member
                • Jan 2012
                • 6

                #37
                No-one has any sample code for logging in with VB???

                I've tried 5-6 different methods and there's nothing that works unless you want to have betfair's home page load up smack in the middle of your nice app. And even if you do, js errors kill it.

                Seriously - this API-NG is useless and a massive step back.

                Comment

                • Tipmanager1
                  Junior Member
                  • Sep 2013
                  • 34

                  #38
                  login via C#

                  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);
                  }
                  }
                  Last edited by Tipmanager1; 11-09-2013, 12:50 PM.

                  Comment

                  • Let it Ride
                    Junior Member
                    • Jan 2012
                    • 6

                    #39
                    Thanks Tipmanager1.

                    Have translated this but a few minor issues - not least that I don't currently have access to use Net 4.5.

                    I've had to revert to the rather backwards embedded Betfair page that they tell you to use. Seems about 5 years outdated but it does produce an SSOID even if you have to instantly close the webbrowser object before all the BF javascript errors kick in on their home page.

                    However the limitations and serious flaws in API-NG mean I think that we will be leaving any conversion until a proper, stable version is available as anything coded now is a wasted effort.

                    Comment

                    • MiloRambaldi
                      Junior Member
                      • Sep 2013
                      • 3

                      #40
                      They uploaded the complete form a couple of days ago. It builds fine now.

                      Comment

                      • MiloRambaldi
                        Junior Member
                        • Sep 2013
                        • 3

                        #41
                        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()
                        {
                        ...
                        }
                        Nice! Thanks.

                        Comment

                        • robne2000
                          Junior Member
                          • May 2013
                          • 19

                          #42
                          So I fire the keep alive URL - how do I know if it worked? I don't get anything back, so do I keep the same SSOID forever, as long as I continue to call keepalive. Or am I doing something wrong?

                          Comment

                          • ununpentium0
                            Junior Member
                            • Oct 2013
                            • 2

                            #43
                            Originally posted by robne2000 View Post
                            So I fire the keep alive URL - how do I know if it worked? I don't get anything back, so do I keep the same SSOID forever, as long as I continue to call keepalive. Or am I doing something wrong?
                            KeepAlive is useless thing for now - it was not implemented correctly.
                            You can't keep the same SSOID forever, because it will expire after seven minutes of using it.

                            Comment

                            • grae
                              Junior Member
                              • Aug 2011
                              • 3

                              #44
                              Hi Vic
                              Yep agree with you. It is difficult at the moment to gather up all the info needed to get started.

                              You can get an App Key here
                              https://api-ng.betstores.com/account/

                              A word of warning... we seem to be limited to only two app keys. One with delay and one without. I had generated both before I new there was a limit. Not sure what this means as I guess the one app key can be used for a multitude of apps

                              Comment

                              • BetfairDeveloperProgram
                                Administrator
                                • Oct 2008
                                • 680

                                #45
                                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

                                Comment

                                Working...
                                X