# HG changeset patch # User Jaroslav Tulach # Date 1289407595 -3600 # Node ID e1d564765efd10dbceab1be0461b1fd6afc64ce0 # Parent c366470a05e17dbeac5e7f769949342455dc7756 Automate login request diff -r c366470a05e1 -r e1d564765efd src/main/java/cz/xelfi/feedbook/Main.java --- a/src/main/java/cz/xelfi/feedbook/Main.java Wed Nov 10 17:26:00 2010 +0100 +++ b/src/main/java/cz/xelfi/feedbook/Main.java Wed Nov 10 17:46:35 2010 +0100 @@ -23,7 +23,13 @@ FacebookJaxbRestClient login = new FacebookJaxbRestClient(APP_KEY, APP_SEC); final String token = login.auth_createToken(); URI u = new URI("http://www.facebook.com/login.php?api_key=" + APP_KEY + "&auth_token=" + token); - System.out.println("authentication: " + u); + String msg = "authentication"; + browser(msg, u); + return login.auth_getSession(token, false); + } + + private static void browser(String msg, URI u) throws IOException { + System.out.println(msg + ": " + u); try { Desktop.getDesktop().browse(u); } catch (Exception ex) { @@ -31,8 +37,6 @@ } System.out.println("Visit the browser and press enter..."); System.in.read(); - - return login.auth_getSession(token, false); } public static void main( String[] args) throws Exception { @@ -62,22 +66,25 @@ break; } - if (fb.users_hasAppPermission(Permission.SHARE_ITEM)) { - Preferences n = prefs.node("feeds"); - for (Object o : rss.getItems()) { - Item item = (Item) o; - String hex = Integer.toHexString(item.getLink().hashCode()); - if (n.getLong(hex, -1L) != -1L) { - continue; - } - System.err.printf("link: %s date: %s title: %s\n", item.getLink(), item.getPubDate(), item.getTitle()); - Long ok = fb.links_post(user, item.getLink(), item.getTitle()); - System.out.println("posted as " + ok); - n.putLong(hex, ok); - n.put(hex + ".url", item.getLink()); + while (!fb.users_hasAppPermission(Permission.SHARE_ITEM)) { + URI u = new URI("https://graph.facebook.com/oauth/authorize?" + + "client_id=" + APP_KEY + + "&redirect_uri=http://www.facebook.com/connect/login_success.html" + + "&scope=publish_stream"); + browser("Need permission to publish links", u); + } + Preferences n = prefs.node("feeds"); + for (Object o : rss.getItems()) { + Item item = (Item) o; + String hex = Integer.toHexString(item.getLink().hashCode()); + if (n.getLong(hex, -1L) != -1L) { + continue; } - } else { - System.out.println("No permission to share links"); + System.err.printf("link: %s date: %s title: %s\n", item.getLink(), item.getPubDate(), item.getTitle()); + Long ok = fb.links_post(user, item.getLink(), item.getTitle()); + System.out.println("posted as " + ok); + n.putLong(hex, ok); + n.put(hex + ".url", item.getLink()); } } }