FileDocCategorySizeDatePackage
ExampleClient.javaAPI DocFacebook API4307Sat Jun 09 21:21:40 BST 2007com.facebook.api

ExampleClient

public class ExampleClient extends Object

Fields Summary
public static final String
CONFIG_FILE
public static final String
REPLACE_MESSAGE
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)
Test main method, just try to get an auth token, which doesn't require a web browser for the user to log in or anything.


                             
         
    FileInputStream fis = new FileInputStream(CONFIG_FILE);
    Properties props = new Properties();
    props.load(fis);

    String api_key = props.getProperty("api_key");
    String secret = props.getProperty("secret");
    if ("<your_api_key>".equals(api_key) || "<your_secret>".equals(secret)) {
      System.out.println( REPLACE_MESSAGE );
    }

    FacebookRestClient client =
      new FacebookRestClient(props.getProperty("api_key"), props.getProperty("secret"));
    String desktop = props.getProperty("desktop");
    if (null != desktop && !"0".equals(desktop))
      client.setIsDesktop(true);

    // uncomment the line below to get details of each request and respnse
    // printed to System.out.
    //  client.setDebug(true);

    String auth = client.auth_createToken();
    BrowserLauncher browserLauncher = new BrowserLauncher(null);
    browserLauncher.openURLinBrowser(props.getProperty("login_url") + "&api_key=" +
                                     props.getProperty("api_key") + "&auth_token=" + auth);
    System.out.println("hit enter after you have logged into FB");
    System.in.read();
    // Thread.sleep(5000); // in ms

    client.auth_getSession(auth);
    Document d = client.friends_get();
    FacebookRestClient.printDom(d, "  ");