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:
@@ -9,7 +9,7 @@
|
||||
<attribute name="javadoc_location" value="http://tcdevsvn1/ShyHookdocumentation"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="LocationLib_src"/>
|
||||
<classpathentry kind="src" path="FacebookLib_src"/>
|
||||
<classpathentry kind="src" path="LocationLib_src"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
||||
@@ -72,7 +72,7 @@ public class FacebookAuth {
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void authorize() {
|
||||
public void authorize() throws NullPointerException {
|
||||
if (!mFb.isSessionValid()) {
|
||||
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
|
||||
}
|
||||
@@ -252,4 +252,12 @@ public class FacebookAuth {
|
||||
Log.i(TAG, "WallPostRequestListener.post successful");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return true if the session is valid
|
||||
* @author ricky barrette
|
||||
*/
|
||||
public boolean isSessionValid() {
|
||||
return mFb.isSessionValid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,12 @@
|
||||
*/
|
||||
package com.TwentyCodes.android.TravelPost;
|
||||
|
||||
import com.TwentyCodes.android.Facebook.FacebookAuth;
|
||||
import com.TwentyCodes.android.Facebook.SessionNotValidException;
|
||||
import com.TwentyCodes.android.location.ReverseGeocoder;
|
||||
|
||||
import twitter4j.TwitterException;
|
||||
import android.app.Activity;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -77,11 +80,26 @@ public class LocationReceiver extends BroadcastReceiver{
|
||||
// TODO check post size, is it greater than 140 chars?
|
||||
|
||||
// TODO Add more social services
|
||||
|
||||
//post to twitter
|
||||
try {
|
||||
Log.d(TravelPost.TAG, TwitterServices.tweet(mContext, thePost).toString());
|
||||
} catch (TwitterException e) {
|
||||
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");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -20,7 +20,6 @@ import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import com.TwentyCodes.android.Facebook.FacebookAuth;
|
||||
import com.TwentyCodes.android.Facebook.SessionNotValidException;
|
||||
import com.TwentyCodes.android.location.LocationService;
|
||||
|
||||
/**
|
||||
@@ -96,9 +95,6 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
|
||||
|
||||
this.findPreference("twitter_sign_in").setOnPreferenceClickListener(this);
|
||||
this.findPreference("facebook_sign_in").setOnPreferenceClickListener(this);
|
||||
// mFbAuth = new FacebookAuth(this, this);
|
||||
// mFbAuth.authorize();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -118,11 +114,13 @@ public class TravelPost extends PreferenceActivity implements OnPreferenceClickL
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else if (preference.getKey().equals("facebook_sign_in")) {
|
||||
try {
|
||||
mFbAuth.postToWall("Another test");
|
||||
} catch (SessionNotValidException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mFbAuth = new FacebookAuth(this, this);
|
||||
mFbAuth.authorize();
|
||||
// try {
|
||||
// mFbAuth.postToWall("Another test");
|
||||
// } catch (SessionNotValidException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
Log.i(TAG, "onPreferenceClick.posted to wall");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user