[tuxdroid-svn] r5769 - in software_suite_v3/software/plugin/plugin-facebook/branches/october_releas
Status: Beta
Brought to you by:
ks156
From: jerome <c2m...@c2...> - 2009-10-26 13:50:53
|
Author: jerome Date: 2009-10-26 14:50:35 +0100 (Mon, 26 Oct 2009) New Revision: 5769 Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java Log: * Fixed autho prompt bug. Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-26 11:12:45 UTC (rev 5768) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookFunctions.java 2009-10-26 13:50:35 UTC (rev 5769) @@ -22,7 +22,6 @@ package com.kysoh.plugins.facebook; - import java.util.Collections; import java.util.Hashtable; import java.util.Iterator; @@ -34,6 +33,8 @@ import com.google.code.facebookapi.FacebookException; import com.google.code.facebookapi.FacebookJsonRestClient; +import com.google.code.facebookapi.Permission; +import com.kysoh.plugins.facebook.connection.FacebookPromptException; public class FacebookFunctions { @@ -68,12 +69,20 @@ /** * Add requested feed to the user wall. */ - public boolean publishFeed(String aFeed) + public boolean publishFeed(String aFeed) throws FacebookPromptException { try { - client.users_setStatus(aFeed); - return true; + if(! client.users_hasAppPermission(Permission.STATUS_UPDATE)) + { + FacebookConnection.promptAuthorizations(); + throw(new FacebookPromptException()); + } + else + { + client.users_setStatus(aFeed); + return true; + } } catch (FacebookException e) { @@ -86,7 +95,7 @@ /** * Return email notifications. */ - public Hashtable<String, Vector<String>> getEmailNotifications() + public Hashtable<String, Vector<String>> getEmailNotifications() throws FacebookPromptException { Hashtable<String, Vector<String>> result = new Hashtable<String, Vector<String>>(); @@ -127,7 +136,9 @@ } catch (FacebookException e) { - ; + e.printStackTrace(); + FacebookConnection.promptAuthorizations(); + throw(new FacebookPromptException()); } catch (JSONException e) { @@ -146,7 +157,7 @@ * Return friend names of friend requests. * @return */ - public Vector<String> getFriendRequests() + public Vector<String> getFriendRequests() throws FacebookPromptException { Vector<String> result = new Vector<String>(); @@ -174,7 +185,8 @@ } catch (FacebookException e) { - ; + FacebookConnection.promptAuthorizations(); + throw(new FacebookPromptException()); } catch (JSONException e) { @@ -425,26 +437,4 @@ return result; } - - - /** - * Return true if our plugin has fb rights. - * @return - */ - public boolean apiGrantedFullAcess() - { - //Trying to read mailbox that is the most important right to have. - String query = "SELECT thread_id FROM thread WHERE folder_id = 0"; - try - { - client.fql_query(query); - return true; - } - catch (FacebookException e) - { - e.printStackTrace(); - //Return false in case of exception, prompt auth was never started. - return false; - } - } } Modified: software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java =================================================================== --- software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-26 11:12:45 UTC (rev 5768) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/FacebookPlugin.java 2009-10-26 13:50:35 UTC (rev 5769) @@ -28,6 +28,7 @@ import com.kysoh.tuxdroid.plugin.framework.plugin.SimplePlugin; import com.kysoh.plugins.facebook.configuration.FacebookDatasStruct; import com.kysoh.plugins.facebook.configuration.PluginFacebookConfiguration; +import com.kysoh.plugins.facebook.connection.FacebookPromptException; import com.kysoh.plugins.facebook.FacebookConnection; @@ -83,14 +84,10 @@ */ public void doConfigure(FacebookFunctions funct) { - //Adding publish stream auth if needed. - if (!functions.apiGrantedFullAcess()) - { - //Prompt web browser for facebook permissions. - this.throwMessage("Please, allow me to access you Facebook account"); - FacebookConnection.promptAuthorizations(); - System.exit( 0 ); - } + //Prompt web browser for facebook permissions. + this.throwMessage("Please, allow me to access you Facebook account"); + FacebookConnection.promptAuthorizations(); + System.exit( 0 ); } @@ -110,12 +107,6 @@ facebookHistory = new FacebookDatasStruct(this.configuration().getLogin()); secondCycle = ( this.getCommand().equalsIgnoreCase("check") && facebookHistory.isFirstCycle() ) ? false : true; - //Checking auth. - if(this.getCommand().equalsIgnoreCase("run")) - { - this.doConfigure(functions); - } - //Updating user status. if(this.configuration().getUpdateStatus()) { @@ -173,14 +164,25 @@ private void updateStatus() { //Updating user status. - if(functions.publishFeed(this.configuration().getStatusText())) + try { - this.throwMessage("Your new status was published"); - } - else + if(functions.publishFeed(this.configuration().getStatusText())) + { + this.throwMessage("Your new status was published"); + } + else + { + this.throwMessage("An error occured trying to set your new status, please, allow me to acces your wall"); + doConfigure(functions); + } + } + catch (FacebookPromptException e) { - this.throwMessage("An error occured trying to set your new status, please, allow me to acces your wall"); - doConfigure(functions); + if( ! this.getCommand().equalsIgnoreCase("check")) + { + this.throwMessage("Please, allo me to access your Facebook account"); + } + System.exit(0); } } @@ -192,7 +194,18 @@ { //Fetching mails. Hashtable<String, Vector<String>> inbox = new Hashtable<String, Vector<String>>(); - inbox = functions.getEmailNotifications(); + try + { + inbox = functions.getEmailNotifications(); + } + catch (FacebookPromptException e) + { + if(this.getCommand().equalsIgnoreCase("check")) + { + this.throwMessage("Please, allo me to access your Facebook account"); + } + System.exit(0); + } Vector<String> keys = new Vector<String>(inbox.keySet()); //Will contain all messages id's that must be added to the history. @@ -261,7 +274,18 @@ { boolean said = false; Vector<String> f_requests = new Vector<String>(); - f_requests = functions.getFriendRequests(); + try + { + f_requests = functions.getFriendRequests(); + } + catch (FacebookPromptException e) + { + if(this.getCommand().equalsIgnoreCase("check")) + { + this.throwMessage("Please, allo me to access your Facebook account"); + } + System.exit(0); + } if (f_requests.size() > 0) { Modified: 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 2009-10-26 11:12:45 UTC (rev 5768) +++ software_suite_v3/software/plugin/plugin-facebook/branches/october_release/src/com/kysoh/plugins/facebook/connection/FacebookSessionUtils.java 2009-10-26 13:50:35 UTC (rev 5769) @@ -67,12 +67,14 @@ public static void setMail(String eMail) { mail = eMail; + sessionUtils.add(eMail); } public static void setPass(String aPass) { - pass = aPass; + pass = aPass; + sessionUtils.add(aPass); } @@ -135,7 +137,7 @@ */ public static String getMail() { - return sessionUtils.get( 2 ); + return (String) sessionUtils.get( 2 ); } @@ -145,7 +147,7 @@ */ public static String getPass() { - return sessionUtils.get( 3 ); + return (String) sessionUtils.get( 3 ); } @@ -178,11 +180,11 @@ try { File path = new File(""); - File session = new File( path.getAbsolutePath() + File.separator + "session"); + File session = new File( path.getAbsolutePath() + File.separator + "session_" + mail); if(session.isFile()) { - FileInputStream fichier = new FileInputStream("session"); + FileInputStream fichier = new FileInputStream("session_" + mail); ObjectInputStream ois = new ObjectInputStream(fichier); sessionUtils = (SerializedVector) ois.readObject(); } @@ -191,6 +193,8 @@ sessionUtils = new SerializedVector(); sessionUtils.add("0"); sessionUtils.add("0"); + sessionUtils.add(mail); + sessionUtils.add(pass); } } catch (java.io.IOException e) @@ -218,7 +222,7 @@ try { File path = new File(""); - File session = new File( path.getAbsolutePath() + File.separator + "session"); + File session = new File( path.getAbsolutePath() + File.separator + "session_" + mail); FileOutputStream file = new FileOutputStream(session.getAbsolutePath()); ObjectOutputStream oos = new ObjectOutputStream(file); oos.writeObject(sessionUtils); |