Author: jerome
Date: 2009-10-19 11:12:03 +0200 (Mon, 19 Oct 2009)
New Revision: 5724

Added:
   
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
Modified:
   
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
Log:
* Added a new way to get connected to the user facebook account ( without 
binary ).

Modified: 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
   2009-10-19 09:10:50 UTC (rev 5723)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookConnection.java
   2009-10-19 09:12:03 UTC (rev 5724)
@@ -22,27 +22,53 @@
 
 package com.kysoh.plugins.facebook;
 
+import java.io.IOException;
+
+import com.google.code.facebookapi.FacebookException;
 import com.google.code.facebookapi.FacebookJsonRestClient;
+import com.kysoh.plugins.facebook.connection.FacebookSessionUtils;
 
 public class FacebookConnection {
 
-       public static String api_key = "a9eb7b7e52df160fb1dfc437b0b487c8";
-       public static String f_key = "0314c8569f89d0411e5a4823372ae27a";
        private FacebookJsonRestClient client;
        
        
-       /**
-        * Class constructor.
-        */
-       public FacebookConnection()
-       {
-               //TODO facebook connection.
-       }
-       
-       
        public boolean Connect(String username, String password)
        {
-               return true;
+               FacebookSessionUtils.setMail(username);
+               FacebookSessionUtils.setPass(password);
+               
+               //Facebook connection stuff.
+               
+               try 
+               {
+                       String sessionKey = 
FacebookSessionUtils.getValidSessionID( true );
+                       
+                       //Generate session secret, ready to pass to desktop app 
client
+                       String sessionSecret = 
FacebookSessionUtils.lastClientUsed.getCacheSessionSecret();
+                       
+                       //TODO remove this one.
+                       System.out.println("Session secret: " + 
String.valueOf(sessionSecret));
+                       
+                       client =  new 
FacebookJsonRestClient(FacebookSessionUtils.api_key, sessionSecret, sessionKey);
+                       
+                       if((sessionSecret == null) || (client == null))
+                       {
+                               return false;
+                       }
+                       
+                       return true;
+               } 
+               catch (FacebookException e) 
+               {
+                       ;
+               } 
+               catch (IOException e) 
+               {
+                       ;
+               }
+               
+               return false;
        }
        
        
@@ -52,7 +78,15 @@
         */
        public Long getFacebookUserId()
        {
-               //TODO
+               try 
+               {
+                       return client.users_getLoggedInUser();
+               } 
+               catch (FacebookException e)
+               {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
                return null;
        }
        
@@ -63,7 +97,6 @@
         */
        public FacebookJsonRestClient getClient()
        {
-               //TODO
-               return null;
+               return client;
        }
 }

Added: 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
===================================================================
--- 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
                              (rev 0)
+++ 
software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java
      2009-10-19 09:12:03 UTC (rev 5724)
@@ -0,0 +1,91 @@
+/* This file is part of "TuxDroid plugin Facebook".
+ *    Copyright 2009, kysoh
+ *    Author : Conan Jerome.
+ *    eMail  : [email protected]
+ *    Site   : http://www.kysoh.com/
+ *
+ * "TuxDroid plugin Facebook" is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * "TuxDroid plugin Facebook" is distributed in the hope that it will be 
useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public
+ * License along with "TuxDroid plugin Facebook"; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package com.kysoh.plugins.facebook.connection;
+
+
+import java.io.IOException;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpState;
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
+
+import com.google.code.facebookapi.FacebookException;
+import com.google.code.facebookapi.FacebookXmlRestClient;
+
+public class FacebookSessionUtils {
+       
+       public static String api_key = "a9eb7b7e52df160fb1dfc437b0b487c8";
+       public static String s_key   = "0314c8569f89d0411e5a4823372ae27a";
+       
+       protected static String mail = "";
+       protected static String pass = "";
+       
+       public static String lastTokenUsed;
+       public static FacebookXmlRestClient lastClientUsed;
+
+       
+       public static void setMail(String eMail)
+       {
+               mail = eMail;
+       }
+       
+       
+       public static void setPass(String aPass)
+       {
+               pass = aPass; 
+       }
+       
+       
+       public static String getValidSessionID( boolean generateSessionSecret) 
+                     throws IOException, FacebookException {
+               
+               
+               FacebookXmlRestClient client = new FacebookXmlRestClient( 
api_key, s_key );
+               String token = client.auth_createToken();
+
+               HttpClient http = new HttpClient();
+        http.setState(new HttpState());
+
+        final String LOGIN = "http://www.facebook.com/login.php";;
+        
+        GetMethod get = new GetMethod(LOGIN + "?api_key=" + api_key + 
"&v=1.0&auth_token=" + token );
+
+        http.executeMethod(get);
+
+        PostMethod post = new PostMethod(LOGIN);
+        post.addParameter(new NameValuePair("api_key", api_key));
+        post.addParameter(new NameValuePair("v", "1.0"));
+        post.addParameter(new NameValuePair("auth_token", token));
+        post.addParameter(new NameValuePair("email", mail));
+        post.addParameter(new NameValuePair("pass", pass));
+
+        http.executeMethod(post);
+
+               String sessionID = client.auth_getSession( token, 
generateSessionSecret );
+               lastTokenUsed = token;
+               lastClientUsed = client;
+               return sessionID;
+       }
+}


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay 
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to