author | Jaroslav Tulach <jtulach@netbeans.org> |
Tue, 09 Nov 2010 21:01:16 +0100 | |
changeset 0 | 258dc96b1636 |
child 1 | 93c350696ff6 |
permissions | -rw-r--r-- |
jtulach@0 | 1 |
package cz.xelfi.feedbook; |
jtulach@0 | 2 |
|
jtulach@0 | 3 |
import com.google.code.facebookapi.FacebookJaxbRestClient; |
jtulach@0 | 4 |
import com.google.code.facebookapi.Permission; |
jtulach@0 | 5 |
import com.google.code.facebookapi.schema.FriendsGetResponse; |
jtulach@0 | 6 |
import com.google.code.facebookapi.schema.User; |
jtulach@0 | 7 |
import com.google.code.facebookapi.schema.UsersGetInfoResponse; |
jtulach@0 | 8 |
import java.net.URI; |
jtulach@0 | 9 |
import java.util.Collections; |
jtulach@0 | 10 |
import java.util.List; |
jtulach@0 | 11 |
|
jtulach@0 | 12 |
public class Main { |
jtulach@0 | 13 |
private static final String APP_KEY = "ecdbd5dbacc168f9edfe470ccd7e401b"; |
jtulach@0 | 14 |
private static final String APP_SEC = "22e3165366e958a6e049e1e0c1d30105"; |
jtulach@0 | 15 |
|
jtulach@0 | 16 |
public static void main( String[] args) throws Exception { |
jtulach@0 | 17 |
FacebookJaxbRestClient login = new FacebookJaxbRestClient(APP_KEY, APP_SEC); |
jtulach@0 | 18 |
final String token = login.auth_createToken(); |
jtulach@0 | 19 |
URI u = new URI("http://www.facebook.com/login.php?api_key=" + APP_KEY + "&auth_token=" + token); |
jtulach@0 | 20 |
Runtime.getRuntime().exec("xdg-open " + u); |
jtulach@0 | 21 |
/* |
jtulach@0 | 22 |
InputStream is = u.toURL().openStream(); |
jtulach@0 | 23 |
for (;;) { |
jtulach@0 | 24 |
int ch = is.read(); |
jtulach@0 | 25 |
if (ch == -1) { |
jtulach@0 | 26 |
break; |
jtulach@0 | 27 |
} |
jtulach@0 | 28 |
System.out.write(ch); |
jtulach@0 | 29 |
} |
jtulach@0 | 30 |
*/ |
jtulach@0 | 31 |
//Desktop.getDesktop().browse(u); |
jtulach@0 | 32 |
System.out.println("Visit the browser and press enter..."); |
jtulach@0 | 33 |
System.in.read(); |
jtulach@0 | 34 |
|
jtulach@0 | 35 |
final String session = login.auth_getSession(token, true); |
jtulach@0 | 36 |
|
jtulach@0 | 37 |
FacebookJaxbRestClient fb = new FacebookJaxbRestClient(APP_KEY, APP_SEC, session); |
jtulach@0 | 38 |
Long user = fb.users_getLoggedInUser(); |
jtulach@0 | 39 |
final FriendsGetResponse ret = fb.friends_get(user); |
jtulach@0 | 40 |
final UsersGetInfoResponse info = fb.users_getInfo(ret.getUid(), Collections.<CharSequence>singleton("last_name")); |
jtulach@0 | 41 |
final List<User> arr = info.getUser(); |
jtulach@0 | 42 |
System.out.println("friends: " + arr.size()); |
jtulach@0 | 43 |
for (int i = 0; i < arr.size(); i++) { |
jtulach@0 | 44 |
System.out.println(" " + i + ". = " + arr.get(i).getLastName()); |
jtulach@0 | 45 |
} |
jtulach@0 | 46 |
|
jtulach@0 | 47 |
String url = "http://apidesign.org"; |
jtulach@0 | 48 |
String cmd = "Testing new application"; |
jtulach@0 | 49 |
|
jtulach@0 | 50 |
if (fb.users_hasAppPermission(Permission.SHARE_ITEM)) { |
jtulach@0 | 51 |
Long ok = fb.links_post(user, url, cmd); |
jtulach@0 | 52 |
System.out.println("posted as " + ok); |
jtulach@0 | 53 |
} else { |
jtulach@0 | 54 |
System.out.println("No permission to share links"); |
jtulach@0 | 55 |
} |
jtulach@0 | 56 |
} |
jtulach@0 | 57 |
} |