My favorites | Sign in
Project Home Downloads Wiki Issues Source
Project Information
Members
Featured
Downloads
Links

Welcome

This is a simple Java library to connect to the AdMob statistics server. With this you can include stats on your specific ads, ad groups, campaigns or sites straight into your Java applications. This was written to support a Windows Desktop Gadget and as such error checking was not very important for us to complete however I have created an exceptions class that you can expand on for your needs.

If you would like to further this project or provide constructive input for changes please feel free to contact me.

Requirements

AdMob Account

  • This library is only useful if you have an active AdMob account which you use to campaign and/or publish advertisements.
JSON
  • The code requires JSON so I have included the library into the project. Check their docs for more information http://www.json.org/java/

Java
  • I wrote this using 1.6 and cannot guarantee it works in any other version however its overall very simple so it should work in most if not all current versions of Java.

Operating System
  • As a Java library it should be OS independent.

Example

Here is an example of how you might use this API. The code shown here logs into your AdMob account, grabs a list of your "house ads" (as a JSON string), then outputs the IDs for those ads, and finally logs back out of your account.

For a complete list of all supported calls visit the AdMob api documentation. http://developer.admob.com/wiki/API

import org.json.JSONArray;
import org.json.JSONObject;

import com.ToxicBakery.AdMobApi.AdMobStats;


public class example {
	
	
	private static final String CLIENT_KEY = "";
	private static final String USERNAME = "";
	private static final String PASSWORD = "";

	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception {
		
		//load the api
		AdMobStats api = new AdMobStats(CLIENT_KEY, USERNAME, PASSWORD);
		
		//attempt to login
		api.login();
		
		//create a request to pull all ads you have setup in admob
		JSONArray allAds = api.getData("ad", "search", new String[0]);
		
		//go through the returned array
		for(int i=0;i<allAds.length();i++){
			//pull the entire line of data
			System.out.println(allAds.get(i));
			
			//convert the line of data to a json object so we can pick specific data out of it
			JSONObject adObject = new JSONObject(allAds.get(i).toString());
			
			//pull the id from the data
			System.out.println(adObject.getString("id"));
		}
		
		//attempt to logout
		api.logout();
		
		//close up
		System.exit(0);
		
	}

}

Additional

The original source code written for this library was generated to be used in conjunction with a (currently underdevelopment) Toxic Bakery product. If you are interested in a real world use of this code please check out our blog for an update.

http://toxicbakery.com

Powered by Google Project Hosting