Initial version of a project that can copy my RSS feed to facebook
authorJaroslav Tulach <jtulach@netbeans.org>
Tue, 09 Nov 2010 21:01:16 +0100
changeset 0258dc96b1636
child 1 93c350696ff6
Initial version of a project that can copy my RSS feed to facebook
.hgignore
pom.xml
src/main/java/cz/xelfi/feedbook/Main.java
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/.hgignore	Tue Nov 09 21:01:16 2010 +0100
     1.3 @@ -0,0 +1,5 @@
     1.4 +\.orig$
     1.5 +\.orig\..*$
     1.6 +\.chg\..*$
     1.7 +\.rej$
     1.8 +\.conflict\~$
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/pom.xml	Tue Nov 09 21:01:16 2010 +0100
     2.3 @@ -0,0 +1,42 @@
     2.4 +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     2.5 +  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
     2.6 +  <modelVersion>4.0.0</modelVersion>
     2.7 +
     2.8 +  <groupId>cz.xelfi</groupId>
     2.9 +  <artifactId>Feedbook</artifactId>
    2.10 +  <version>0.1</version>
    2.11 +  <packaging>jar</packaging>
    2.12 +
    2.13 +  <name>Feedbook</name>
    2.14 +  <url>http://maven.apache.org</url>
    2.15 +    <build>
    2.16 +        <plugins>
    2.17 +            <plugin>
    2.18 +                <groupId>org.apache.maven.plugins</groupId>
    2.19 +                <artifactId>maven-compiler-plugin</artifactId>
    2.20 +                <version>2.0.2</version>
    2.21 +                <configuration>
    2.22 +                    <source>1.6</source>
    2.23 +                    <target>1.6</target>
    2.24 +                </configuration>
    2.25 +            </plugin>
    2.26 +        </plugins>
    2.27 +    </build>
    2.28 +    <properties>
    2.29 +    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    2.30 +  </properties>
    2.31 +
    2.32 +  <dependencies>
    2.33 +    <dependency>
    2.34 +      <groupId>junit</groupId>
    2.35 +      <artifactId>junit</artifactId>
    2.36 +      <version>3.8.1</version>
    2.37 +      <scope>test</scope>
    2.38 +    </dependency>
    2.39 +    <dependency>
    2.40 +      <groupId>com.google.code.facebookapi</groupId>
    2.41 +      <artifactId>facebook-java-api</artifactId>
    2.42 +      <version>3.0.4</version>
    2.43 +    </dependency>
    2.44 +  </dependencies>
    2.45 +</project>
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/main/java/cz/xelfi/feedbook/Main.java	Tue Nov 09 21:01:16 2010 +0100
     3.3 @@ -0,0 +1,57 @@
     3.4 +package cz.xelfi.feedbook;
     3.5 +
     3.6 +import com.google.code.facebookapi.FacebookJaxbRestClient;
     3.7 +import com.google.code.facebookapi.Permission;
     3.8 +import com.google.code.facebookapi.schema.FriendsGetResponse;
     3.9 +import com.google.code.facebookapi.schema.User;
    3.10 +import com.google.code.facebookapi.schema.UsersGetInfoResponse;
    3.11 +import java.net.URI;
    3.12 +import java.util.Collections;
    3.13 +import java.util.List;
    3.14 +
    3.15 +public class Main {
    3.16 +    private static final String APP_KEY = "ecdbd5dbacc168f9edfe470ccd7e401b";
    3.17 +    private static final String APP_SEC = "22e3165366e958a6e049e1e0c1d30105";
    3.18 +    
    3.19 +    public static void main( String[] args) throws Exception {
    3.20 +        FacebookJaxbRestClient login = new FacebookJaxbRestClient(APP_KEY, APP_SEC);
    3.21 +        final String token = login.auth_createToken();
    3.22 +        URI u = new URI("http://www.facebook.com/login.php?api_key=" + APP_KEY + "&auth_token=" + token);
    3.23 +        Runtime.getRuntime().exec("xdg-open " + u);
    3.24 +        /*
    3.25 +        InputStream is = u.toURL().openStream();
    3.26 +        for (;;) {
    3.27 +            int ch = is.read();
    3.28 +            if (ch == -1) {
    3.29 +                break;
    3.30 +            }
    3.31 +            System.out.write(ch);
    3.32 +        }
    3.33 +         */
    3.34 +        //Desktop.getDesktop().browse(u);
    3.35 +        System.out.println("Visit the browser and press enter...");
    3.36 +        System.in.read();
    3.37 +        
    3.38 +        final String session = login.auth_getSession(token, true); 
    3.39 +        
    3.40 +        FacebookJaxbRestClient fb = new FacebookJaxbRestClient(APP_KEY, APP_SEC, session);
    3.41 +        Long user = fb.users_getLoggedInUser();
    3.42 +        final FriendsGetResponse ret = fb.friends_get(user);
    3.43 +        final UsersGetInfoResponse info = fb.users_getInfo(ret.getUid(), Collections.<CharSequence>singleton("last_name"));
    3.44 +        final List<User> arr = info.getUser();
    3.45 +        System.out.println("friends: " + arr.size());
    3.46 +        for (int i = 0; i < arr.size(); i++) {
    3.47 +            System.out.println("  " + i + ". = " + arr.get(i).getLastName());
    3.48 +        }
    3.49 +        
    3.50 +        String url = "http://apidesign.org";
    3.51 +        String cmd = "Testing new application";
    3.52 +
    3.53 +        if (fb.users_hasAppPermission(Permission.SHARE_ITEM)) {
    3.54 +            Long ok = fb.links_post(user, url, cmd);
    3.55 +            System.out.println("posted as " + ok);
    3.56 +        } else {
    3.57 +            System.out.println("No permission to share links");
    3.58 +        }
    3.59 +    }
    3.60 +}