com.akdeniz.googleplaycrawler.GooglePlayAPI Java Examples

The following examples show how to use com.akdeniz.googleplaycrawler.GooglePlayAPI. 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: 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 #2
Source File: SearchWorker.java    From Raccoon with Apache License 2.0 6 votes vote down vote up
private Vector<BulkDetailsEntry> doQuerySearch() throws Exception {
	GooglePlayAPI service = App.createConnection(archive);
	service.setLocalization(localization);
	SearchResponse response = service.search(search, offset, limit);

	List<String> apps = new Vector<String>();
	if (response.getDocCount() > 0) {
		DocV2 all = response.getDoc(0);
		for (int i = 0; i < all.getChildCount(); i++) {
			apps.add(all.getChild(i).getBackendDocid());
			if (fetchIcons) {
				fetchIcon(all.getChild(i));
			}
		}
	}
	BulkDetailsResponse bdr = service.bulkDetails(apps);
	Vector<BulkDetailsEntry> ret = new Vector<BulkDetailsEntry>();
	for (int i = 0; i < bdr.getEntryCount(); i++) {
		ret.add(bdr.getEntry(i));
	}
	return ret;
}
 
Example #3
Source File: SearchWorker.java    From Raccoon with Apache License 2.0 6 votes vote down vote up
private Vector<BulkDetailsEntry> doUpdateSearch() throws Exception {
	GooglePlayAPI service = App.createConnection(archive);
	BulkDetailsResponse response = service.bulkDetails(archive.list());
	Vector<BulkDetailsEntry> ret = new Vector<BulkDetailsEntry>();
	for (BulkDetailsEntry bulkDetailsEntry : response.getEntryList()) {
		DocV2 doc = bulkDetailsEntry.getDoc();
		String pn = doc.getBackendDocid();
		int vc = doc.getDetails().getAppDetails().getVersionCode();
		if (!archive.fileUnder(pn, vc).exists()) {
			ret.add(bulkDetailsEntry);
		}
		if (fetchIcons) {
			fetchIcon(doc);
		}
	}
	return ret;
}
 
Example #4
Source File: PlayManager.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
/**
 * Create a connection object for accessing Google Play, using an arbitrary
 * profile
 * 
 * @param profile
 *          the profile to use for connecting
 * @return a connection according to the submitted profile
 */
public static GooglePlayAPI createConnection(PlayProfile profile) {
	GooglePlayAPI ret = new GooglePlayAPI(profile.getUser(),
			profile.getPassword());
	ret.setUseragent(profile.getAgent());
	ret.setAndroidID(profile.getGsfId());
	ret.setToken(profile.getToken());
	Locale l = Locale.getDefault();
	String s = l.getLanguage();
	if (l.getCountry() != null) {
		s = s + "-" + l.getCountry();
	}
	ret.setLocalization(s);
	try {
		HttpClient proxy = createProxyClient(profile);
		if (proxy != null) {
			ret.setClient(proxy);
		}
	}
	catch (Exception e) {
		e.printStackTrace();
	}
	return ret;
}
 
Example #5
Source File: AppDownloadWorker.java    From raccoon4 with Apache License 2.0 6 votes vote down vote up
@Override
public void onPrepare() throws Exception {
	GooglePlayAPI api = globals.get(PlayManager.class).createConnection();

	if (paid) {
		// For apps that must be purchased before download
		data = api.delivery(packageName, versionCode, offerType);
	}
	else {
		// for apps that can be downloaded free of charge.
		data = api.purchaseAndDeliver(packageName, versionCode, offerType);
	}
	data.setCompress(globals.get(Traits.class).isAvailable("4.0.x"));

	this.totalBytes = data.getTotalSize();
	apkFile = new AppInstallerNode(layout, packageName, versionCode).resolve();
	apkFile.getParentFile().mkdirs();
	iconFile = new AppIconNode(layout, packageName, versionCode).resolve();
	mainFile = new AppExpansionMainNode(layout, packageName,
			data.getMainFileVersion()).resolve();
	patchFile = new AppExpansionPatchNode(layout, packageName,
			data.getPatchFileVersion()).resolve();
	splitCount = data.getSplitCount();
	
}
 
Example #6
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 #7
Source File: Play.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
public static void search(String query) {
	GooglePlayAPI api = createConnection();
	try {
		System.out.println(api.search(query));
	}
	catch (Exception e) {
		Router.fail("play.exception", e.getMessage());
	}
}
 
Example #8
Source File: DetailsWorker.java    From Raccoon with Apache License 2.0 5 votes vote down vote up
@Override
protected DocV2 doInBackground() throws Exception {
	publish("");
	GooglePlayAPI service = App.createConnection(archive);
	service.setLocalization(Locale.getDefault().getCountry());
	return service.details(appId).getDocV2();
}
 
Example #9
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;
}
 
Example #10
Source File: DownloadTest.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
@Test
public void test() throws SQLException, IOException {
	DatabaseManager dbm = new DatabaseManager(Layout.DEFAULT.databaseDir);
	PlayManager pm = new PlayManager(dbm);
	GooglePlayAPI api = pm.createConnection();
	//DownloadData data = api.purchaseAndDeliver("com.irccloud.android",207,1);
	DownloadData data = api.purchaseAndDeliver("onyxbits.de.testapp",2,1);
	System.err.println(data);
}
 
Example #11
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 #12
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 #13
Source File: Play.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * Perform a details query, print the raw results to stdout
 * 
 * @param name
 *          packagename
 */
public static void details(String name) {
	GooglePlayAPI api = createConnection();
	try {
		System.out.println(api.details(name));
	}
	catch (Exception e) {
		Router.fail("play.exception", e.getMessage());
	}
}
 
Example #14
Source File: PlayManager.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
/**
 * Create a connection object for accessing Google Play, using the currently
 * active profile.
 * 
 * @return a connection according to the active profile settings.
 */
public GooglePlayAPI createConnection() {
	PlayProfile active = databaseManager.get(PlayProfileDao.class).get();
	if (active == null) {
		// Semi error state.
		return new GooglePlayAPI();
	}
	return createConnection(active);
}
 
Example #15
Source File: UpdateAppWorker.java    From raccoon4 with Apache License 2.0 5 votes vote down vote up
private Integer update(List<AndroidApp> apps, PlayProfile profile)
		throws IOException {

	int number = 0;
	List<String> pns = new ArrayList<String>(apps.size());
	HashMap<String, AndroidApp> map = new HashMap<String, AndroidApp>();
	for (AndroidApp app : apps) {
		// Note: this check should not exist.
		if (app.getPackageName() != null && !app.getPackageName().equals("")
				&& !pns.contains(app.getPackageName())) {
			pns.add(app.getPackageName());
			map.put(app.getPackageName(), app);
		}
		System.out.println(app.getAppId()+" "+app.getPackageName());
	}
	GooglePlayAPI api = PlayManager.createConnection(profile);

	BulkDetailsResponse response = api.bulkDetails(pns);
	List<BulkDetailsEntry> bde = response.getEntryList();
	for (BulkDetailsEntry entry : bde) {
		DocV2 doc = entry.getDoc();
		AppDetails ad = entry.getDoc().getDetails().getAppDetails();
		String pn = ad.getPackageName();
		if (map.containsKey(pn)) {
			int lvc = map.get(pn).getVersionCode();
			int rvc = ad.getVersionCode();
			if (lvc < rvc) {
				globals.get(TransferManager.class).schedule(globals,
						new AppDownloadWorker(globals, doc), TransferManager.WAN);
				number++;
			}
		}
	}
	return number;
}
 
Example #16
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 #17
Source File: Play.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
public static void updateApps() {
	DatabaseManager dbm = getDatabase();
	PlayAppOwnerDao pad = dbm.get(PlayAppOwnerDao.class);
	List<AndroidApp> apps = pad.list(getProfile());
	List<String> pns = new ArrayList<String>(apps.size());
	HashMap<String, AndroidApp> map = new HashMap<String, AndroidApp>();
	for (AndroidApp app : apps) {
		// Note: this check should not exist.
		if (app.getPackageName() != null && !app.getPackageName().equals("")
				&& !pns.contains(app.getPackageName())) {
			pns.add(app.getPackageName());
			map.put(app.getPackageName(), app);
		}
	}
	GooglePlayAPI api = createConnection();
	try {
		BulkDetailsResponse response = api.bulkDetails(pns);
		List<BulkDetailsEntry> bde = response.getEntryList();
		for (BulkDetailsEntry entry : bde) {
			AppDetails ad = entry.getDoc().getDetails().getAppDetails();
			String pn = ad.getPackageName();
			int rvc = ad.getVersionCode();
			if (map.containsKey(pn)) {
				int lvc = map.get(pn).getVersionCode();
				if (lvc < rvc) {
					System.out.println("^\t" + pn + "\t" + lvc + "\t->\t" + rvc);
					downloadApp(pn, rvc, 1);
				}
				else {
					System.out.println("=\t" + pn + "\t" + lvc + "\t->\t" + rvc);
				}
			}
			else {
				System.out.println("?\t" + pn + "\t0\t->\t" + rvc);
			}
		}
	}
	catch (IOException e) {
		Router.fail(e.getMessage());
		e.printStackTrace();
	}
}
 
Example #18
Source File: Play.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
private static GooglePlayAPI createConnection() {
	return PlayManager.createConnection(getProfile());
}
 
Example #19
Source File: ImportWorker.java    From raccoon4 with Apache License 2.0 4 votes vote down vote up
@Override
protected List<BulkDetailsEntry> doInBackground() throws Exception {
	GooglePlayAPI service = globals.get(PlayManager.class).createConnection();
	return service.bulkDetails(packs).getEntryList();
}
 
Example #20
Source File: SearchAppWorker.java    From raccoon4 with Apache License 2.0 3 votes vote down vote up
/**
 * 
 * @param api
 *          connection object.
 * @param query
 *          what to search for
 * @param offset
 *          start after offset
 * @param limit
 *          number of entries
 */
public SearchAppWorker(PlayManager owner, GooglePlayAPI api, String query,
		SearchEngineResultPage serp) {
	this.api = api;
	this.query = query;
	this.owner = owner;
	this.serp = serp;
}