Java Code Examples for com.akdeniz.googleplaycrawler.GooglePlayAPI#login()

The following examples show how to use com.akdeniz.googleplaycrawler.GooglePlayAPI#login() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UploadLogic.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDoInBackground() {
	PlayProfile pp = globals.get(PlayProfile.class);

	if (pp.getAgent() == null) {
		// TODO: rewrite the GooglePlayAPI. The whole device config stuff is
		// hardcoded and poorly exposed.
		pp.setAgent(new GooglePlayAPI("", "").getUseragent());
	}

	GooglePlayAPI api = PlayManager.createConnection(pp);
	api.setClient(LoginLogic.createLoginClient());
	try {
		if (pp.getGsfId() == null) {
			api.checkin(); // Generates the GSF ID
			api.login();
			api.uploadDeviceConfig();
			pp.setGsfId(api.getAndroidID());
		}
	}
	catch (Exception e) {
		err = e;
		e.printStackTrace();
	}
}
 
Example 2
Source File: InitWorker.java    From Raccoon with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground() throws Exception {
	publish("");
	// Register the account with GPlay.
	GooglePlayAPI service = App.createConnection(archive);
	service.setLocalization(Locale.getDefault().getCountry());
	if ("".equals(archive.getAndroidId())) {
		service.checkin();
		service.login();
		service.uploadDeviceConfig();
	}
	else {
		service.login();
	}
	// Persist credentials through a separate object...
	Archive a = new Archive(archive.getRoot());
	a.setUserId(archive.getUserId());
	a.setPassword(archive.getPassword());
	a.setAndroidId(service.getAndroidID());
	a.saveCredentials();
	// ... and transport back the new aid, so we only modify the submitted
	// archive on the UI thread.
	return service.getAndroidID();
}
 
Example 3
Source File: LoginLogic.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
public void onDoInBackground() {
	err = null;
	try {
		PlayProfile pp = globals.get(PlayProfile.class);
		GooglePlayAPI api = PlayManager.createConnection(pp);
		api.setClient(createLoginClient());
		api.login();
		pp.setToken(api.getToken());
	}
	catch (Exception e) {
		err = e;
	}
}
 
Example 4
Source File: Play.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
public static void auth() {
	PlayProfile pp = getProfile();
	GooglePlayAPI api = createConnection();
	try {
		api.login();
		pp.setToken(api.getToken());
		getDatabase().get(PlayProfileDao.class).update(pp);
	}
	catch (Exception e) {
		e.printStackTrace();
		Router.fail("");
	}
}
 
Example 5
Source File: NewProfile.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws Exception {
	String uid = System.getProperty("raccoon.dev.gmail");
	assertNotNull("No credentials!", uid);
	String pwd = System.getProperty("raccoon.dev.gmail.pw");
	assertNotNull("No credentials!", pwd);
	GooglePlayAPI api = new GooglePlayAPI(uid, pwd);
	api.login();
	api.checkin();
	api.uploadDeviceConfig();
	System.out.println(api.details("de.onyxbits.listmyapps"));
}
 
Example 6
Source File: App.java    From Raccoon with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method for hooking up with Google Play.
 * 
 * @param archive
 *          The archive from which to take configuration data.
 * @return a ready to use connection
 * @throws Exception
 *           if something goes seriously wrong.
 */
public static synchronized GooglePlayAPI createConnection(Archive archive) throws Exception {
	String pwd = archive.getPassword();
	String uid = archive.getUserId();
	String aid = archive.getAndroidId();
	String ua = archive.getUserAgent();
	GooglePlayAPI ret = new GooglePlayAPI(uid, pwd, aid);
	if (ua != null) {
		ret.setUseragent(ua);
	}

	HttpClient client = archive.getProxyClient();
	if (client != null) {
		ret.setClient(client);
	}
	// I am not quite sure if this method needs to be synchronized, but if so,
	// this is why:
	ret.setToken(archive.getAuthToken());
	if (ret.getToken() == null) {
		ret.login();
		// Caching the token considerably speeds up talking to the server, but
		// since multiple downloaders may be active at the same time and the
		// network may produce all kinds of timing effects, there is a good chance
		// that two threads would try to connect at the same time. Both see that
		// the token is not yet available and perform a login. Thread A logs in
		// first, but B's token returns faster. This results in B's token being
		// overwritten by A. This is a problem if the tokens are different and
		// only the latest one is valid. I'm not sure if this is the case, but
		// serializing connection requests prevents potential trouble.
		archive.setAuthToken(ret.getToken());
	}
	return ret;
}