changed postToWall() to postWall() in FacebookAuth.java.
created method postToWall(). this method should post without user interaction in FacebookAuth.java i splite the init() method into two. authorize() and logout(). created postToWallDialog() in FacebookAuth.java to display a dialog when posting to wall. created a custom exception called SessionNotValidException to be thrown when facebook hates us t seems the facebook sdk is not saving an access token when trying to make a direct facebook graph request. it does save the access token when calling a dialog but prompts for credentials. i believe the authorization process is failing. not sure why. still researching.
This commit is contained in:
@@ -24,7 +24,7 @@ public class FacebookAuth {
|
||||
|
||||
private static final String[] PERMISSIONS = new String[] {"publish_stream"};
|
||||
/* Permissions that are prompted to the user for authorization */
|
||||
private static final String APP_ID = "160048987380834";
|
||||
private static final String APP_ID = "197267276952565";
|
||||
/* This is the api key for the facebook application. See /FacebookLib/APIS.txt */
|
||||
private static final String TAG = "FacebookAuth";
|
||||
private Facebook mFb;
|
||||
@@ -57,23 +57,76 @@ public class FacebookAuth {
|
||||
public void init() {
|
||||
Log.i(TAG, "init()");
|
||||
if (mFb.isSessionValid()) {
|
||||
SessionEvents.onLogoutBegin();
|
||||
mAsyncRunner.logout(mCtx, new LogoutRequestListener());
|
||||
/*
|
||||
*These lines log out you out of facebook. For now commented out.
|
||||
*/
|
||||
// SessionEvents.onLogoutBegin();
|
||||
// mAsyncRunner.logout(mCtx, new LogoutRequestListener());
|
||||
} else {
|
||||
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method posts a message to the wall
|
||||
* @param message
|
||||
* This method authorizes the facebook account
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void postToWall(String message) {
|
||||
Log.i(TAG, "postToWall()");
|
||||
Bundle parameters = new Bundle();
|
||||
parameters.putString("message", message);
|
||||
mFb.dialog(mCtx, "stream.publish", parameters, new FacebookDialogListener());
|
||||
public void authorize() {
|
||||
if (!mFb.isSessionValid()) {
|
||||
mFb.authorize(mActivity, PERMISSIONS, new LoginDialogListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method starts the logout process
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void logout() {
|
||||
if (mFb.isSessionValid()) {
|
||||
SessionEvents.onLogoutBegin();
|
||||
mAsyncRunner.logout(mCtx, new LogoutRequestListener());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method posts a message to the users wall
|
||||
* @author warren
|
||||
* @param msg - message to post
|
||||
*/
|
||||
|
||||
public void postToWall(String msg) throws SessionNotValidException {
|
||||
Log.d(TAG, "Testing graph API wall post");
|
||||
if (mFb.isSessionValid()) {
|
||||
try {
|
||||
String response = mFb.request("me");
|
||||
Bundle parameters = new Bundle();
|
||||
parameters.putString("message", msg);
|
||||
parameters.putString("description", "test test test");
|
||||
response = mFb.request("me/feed", parameters, "POST");
|
||||
Log.d(TAG, "got response: " + response);
|
||||
if (response == null || response.equals("") || response.equals("false")) {
|
||||
Log.v("Error", "Blank response");
|
||||
}
|
||||
} catch(Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
if (mFb.getAccessToken() == null) {
|
||||
Log.i(TAG, "postToWall.access token is null");
|
||||
}
|
||||
throw new SessionNotValidException("This session is not valid");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows the user to post to their wall and input their own message
|
||||
* @author warren
|
||||
*/
|
||||
|
||||
public void postToWallDialog() {
|
||||
mFb.dialog(mCtx, "feed", new FacebookDialogListener());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package com.TwentyCodes.android.Facebook;
|
||||
|
||||
import android.accounts.AccountsException;
|
||||
|
||||
public class SessionNotValidException extends AccountsException {
|
||||
|
||||
/**
|
||||
* generated id
|
||||
*/
|
||||
private static final long serialVersionUID = 624797017013181185L;
|
||||
|
||||
public SessionNotValidException(String message) {
|
||||
new AccountsException(message);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user