trungvothanh / betfair-api

Automatically exported from code.google.com/p/betfair-api
0 stars 0 forks source link

Using BetFair API without Spring - Login issue #6

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Hi,

I am trying to use BetFair API without Spring Framework using pure Java. Here 
is my sample code. Unfortunately I can't get pass the Login phase:

  // code
  BetFairServiceImpl service = new BetFairServiceImpl();
  service.setUser("username");
  service.setProductId(82);
  service.setPassword("password");

  LoginResponse res = service.login();
  System.out.println(res.getLoginStatusCode());

 // Ouputs:
 // INFO: Login error.User: username, ProductId: 82, apiCode: null, loginCode: null, exception: null

Why is loginCode null?

Original issue reported on code.google.com by vlada...@gmail.com on 11 Dec 2012 at 8:30

GoogleCodeExporter commented 8 years ago
You are not setting dependencies to BetfairServiceImpl object: 
setExchangeWebService(BFExchangeService exchangeWebService) and 
setGlobalWebService(BFGlobalService globalWebService).

The best way for creating BetfairServiceImpl instance is to use  
DefaultBetFairServiceFactoryBean factory, e.g.

factory = new  DefaultBetFairServiceFactoryBean()
betfairService = (BetfairService)factory.getObject()

Then,
betfairService.setUser
betfairService.setPassword
betfairService.setProductId
betfairService.login
betfairService.getMarkets

DefaultBetFairServiceFactoryBean uses Spring internally to instantiate all 
required beans. If you really don't want using Spring, then you would need to 
create exchangeWebService and globalWebService objects yourself and pass them 
to BetfairServiceImpl instance.

Hope it helps.

Original comment by daniel.k...@gmail.com on 11 Dec 2012 at 9:21