Created
July 30, 2012 11:49
-
-
Save dugjason/3206398 to your computer and use it in GitHub Desktop.
Short Java example using the Java API client to get your recent API usage stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This example returns your stream usage for the last hour. You can edit the | |
* usage period by passing "hour" or "day" in the getUsage() method. | |
*/ | |
package org.datasift.examples; | |
import org.datasift.*; | |
/** | |
* @author MediaSift | |
* @version 0.1 | |
*/ | |
public class getUsage { | |
/** | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
try { | |
// Authenticate | |
System.out.println("Creating user..."); | |
User user = new User(Config.username, Config.api_key); | |
// Call the getUsage method | |
Usage usage = user.getUsage(); | |
// And start consuming | |
System.out.println("Current usage..."); | |
System.out.println("--"); | |
System.out.println(usage); | |
} catch (EInvalidData e) { | |
System.out.print("InvalidData: "); | |
System.out.println(e.getMessage()); | |
} catch (EAPIError e) { | |
System.out.print("InvalidData: "); | |
System.out.println(e.getMessage()); | |
} catch (EAccessDenied e) { | |
System.out.print("AccessDenied: "); | |
System.out.println(e.getMessage()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment