I have got FB auth to work properly in the settings, also i was able to post to facebook with out user interaction.

I intergrated facebok posting into LocationReceiver.java and have successfully posted my location to my wall as travel post.

i am having issues with receiver crashing when trying to post to facebook, if facebook isnt authorized yet.

im thinking of using a shared_prefs to save whether or not if facebook has been authorized
This commit is contained in:
2011-02-12 17:54:34 +00:00
parent ff0e2a287e
commit 3bf935095b
4 changed files with 36 additions and 12 deletions

View File

@@ -9,7 +9,7 @@
<attribute name="javadoc_location" value="http://tcdevsvn1/ShyHookdocumentation"/> <attribute name="javadoc_location" value="http://tcdevsvn1/ShyHookdocumentation"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="LocationLib_src"/>
<classpathentry kind="src" path="FacebookLib_src"/> <classpathentry kind="src" path="FacebookLib_src"/>
<classpathentry kind="src" path="LocationLib_src"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@@ -72,7 +72,7 @@ public class FacebookAuth {
* @author warren * @author warren
*/ */
public void authorize() { public void authorize() throws NullPointerException {
if (!mFb.isSessionValid()) { if (!mFb.isSessionValid()) {
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener()); mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
} }
@@ -252,4 +252,12 @@ public class FacebookAuth {
Log.i(TAG, "WallPostRequestListener.post successful"); Log.i(TAG, "WallPostRequestListener.post successful");
} }
} }
/**
* @return true if the session is valid
* @author ricky barrette
*/
public boolean isSessionValid() {
return mFb.isSessionValid();
}
} }

View File

@@ -6,9 +6,12 @@
*/ */
package com.TwentyCodes.android.TravelPost; package com.TwentyCodes.android.TravelPost;
import com.TwentyCodes.android.Facebook.FacebookAuth;
import com.TwentyCodes.android.Facebook.SessionNotValidException;
import com.TwentyCodes.android.location.ReverseGeocoder; import com.TwentyCodes.android.location.ReverseGeocoder;
import twitter4j.TwitterException; import twitter4j.TwitterException;
import android.app.Activity;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@@ -77,11 +80,26 @@ public class LocationReceiver extends BroadcastReceiver{
// TODO check post size, is it greater than 140 chars? // TODO check post size, is it greater than 140 chars?
// TODO Add more social services // TODO Add more social services
//post to twitter
try { try {
Log.d(TravelPost.TAG, TwitterServices.tweet(mContext, thePost).toString()); Log.d(TravelPost.TAG, TwitterServices.tweet(mContext, thePost).toString());
} catch (TwitterException e) { } catch (TwitterException e) {
e.printStackTrace(); e.printStackTrace();
} }
//post to facebook
FacebookAuth fbAuth = new FacebookAuth(mContext, new Activity());
fbAuth.authorize();
if(fbAuth.isSessionValid())
try {
fbAuth.postToWall(thePost);
} catch (SessionNotValidException e) {
e.printStackTrace();
}
else
Log.d(TravelPost.TAG, "cant post to FB, not auth'd");
} }
/** /**

View File

@@ -20,7 +20,6 @@ import android.util.Log;
import android.widget.RemoteViews; import android.widget.RemoteViews;
import com.TwentyCodes.android.Facebook.FacebookAuth; import com.TwentyCodes.android.Facebook.FacebookAuth;
import com.TwentyCodes.android.Facebook.SessionNotValidException;
import com.TwentyCodes.android.location.LocationService; import com.TwentyCodes.android.location.LocationService;
/** /**
@@ -95,10 +94,7 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
this.addPreferencesFromResource(R.xml.settings); this.addPreferencesFromResource(R.xml.settings);
this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this); this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this);
this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this); this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this);
// mFbAuth = new FacebookAuth(this, this);
// mFbAuth.authorize();
} }
@Override @Override
@@ -118,11 +114,13 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
e.printStackTrace(); e.printStackTrace();
} }
} else if (preference.getKey().equals("facebook_sign_in")) { } else if (preference.getKey().equals("facebook_sign_in")) {
try { mFbAuth = new FacebookAuth(this, this);
mFbAuth.postToWall("Another test"); mFbAuth.authorize();
} catch (SessionNotValidException e) { // try {
e.printStackTrace(); // mFbAuth.postToWall("Another test");
} // } catch (SessionNotValidException e) {
// e.printStackTrace();
// }
Log.i(TAG, "onPreferenceClick.posted to wall"); Log.i(TAG, "onPreferenceClick.posted to wall");
} }