Facebook 'feed' dialog disappears and stops the calling activity - Android - android

In one of the activities in my Android app I want the user to be able to post something to there wall on facebook. So far I have successfully allowed the user to log in using facebook..authorize(this, new DialogListener() { ... and this seems to work fine.
Now I am trying to use the following code in a Button onClickListener to allow the user to post something to there own wall.
facebook.dialog(this, "feed", new DialogListener() {
#Override
public void onComplete(Bundle values) {
}
#Override
public void onFacebookError(FacebookError e) {
// TODO Auto-generated method stub
Log.v("error", e.toString());
}
#Override
public void onError(DialogError e) {
Log.v("error", e.toString());
}
#Override
public void onCancel() {
}});
It appears to work as it shows the dialog but it disappears after about 2 or 3 seconds and also seems to close the activity from where it was called.
Logcat isn't very helpful... the last log just prints the url and doesn't show an error or anything. What am I doing wrong?

Looks like its the same issue as this:
http://developers.facebook.com/bugs/282710765082535
Except that I was using Android 2.1. Changed to 2.2 and it now works fine

Related

How do the App knows whether the user did a Facebook POST or DISCARD

In my Android Game,I am using Facebook SDK to share the open graph story. When the user sees the sharin screen. The user may post it or it can be discarded by pressing the back button.
After the user returs to the game, I need to know whether the user has posted the story or discarded it. I need to reward the user if he shares it.
For now, I use the below code to know the status. The code reaches onSuccess() even for POST or DISCARD.
Code
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
//always gets called
socialShareType=FB_SHARE;
System.out.println("socialShareType in FB onSuccess : " + socialShareType);
Log.d("FBshare", "Share done Successfully");
}
#Override
public void onCancel() {
Log.d("FBshare", "Share cancelled");
}
#Override
public void onError(FacebookException error) {
// TODO Auto-generated method stub
Log.d("FBshare", "Share error");
}
});

Facebook Android SDK Login Dialog title bar issue

I've integrated the Facebook Android SDK with my application.
I want to remove the title bar from all screens in the app, including the screen in which the FB login dialog appears.
I've used the following code in the manifest.
<activity android:name=".FacebookScreen"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"></activity>
FB Login code:
if (!facebook.isSessionValid()) {
facebook.authorize(FacebookScreen.this.getParent(),
new String[] { "publish_stream" },
Facebook.FORCE_DIALOG_AUTH,
new DialogListener() {
public void onCancel() {
// Function to handle cancel event
}
#Override
public void onComplete(Bundle values) {
// Function to handle complete event
new MyAsyncTask().execute();
}
#Override
public void onError(DialogError error) {
// Function to handle error
Log.i("Login DialogError", error.getMessage());
}
#Override
public void onFacebookError(FacebookError fberror) {
// Function to handle Facebook errors
Log.i("Login Error", fberror.getMessage());
}
});
}
But still, I can see the default title bar appearing, when the FB Login dialog appears.
I tried to add the following line of code inside the onCreate method in com.facebook.LoginActivity
requestWindowFeature(Window.FEATURE_NO_TITLE);
But that doesn't help either. How to remove that?

Android - Facebook login

I've got some problem implementing Facebook login.
If I create the Facebook object with an existing api key,i got some intresting thing. If I run the activity on a real device, after clicking on the button, appears Facebbok, it loads, but before I could see the wall it disappears. If I try to run the activity in emulator, facebook's isSessionValid returns true, so seems like I managed to log in. But login screen doesn't appears, and even any view /webview or facebook app/ does not appears.
If I create Facebook object without api key (Facebook facebook = new Facebook("APIKEY");)
both on the phone and the emulator a webview appears with facebook login screen, if i was logged out, or with the facebook page if i was logged in. In this case I can't get any information about the session, so isSessionValid always returns with false . But in this case, at least I can see login page and facebook actually.
fButton = (ImageButton) findViewById(R.id.login);
fButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
facebook.authorize(FbLogin.this,
new Facebook.DialogListener() {
public void onFacebookError(FacebookError e) {
Toast.makeText(getApplicationContext(),
"fberror", Toast.LENGTH_SHORT).show();
}
public void onError(DialogError e) {
Toast.makeText(getApplicationContext(),
"dialogerror", Toast.LENGTH_SHORT)
.show();
}
public void onComplete(Bundle values) {
}
public void onCancel() { // TODO Auto-generated
// method stub
}
});
}
});
and i would like to check the session with the following method:
void check(){
if (facebook.isSessionValid()) {
System.out.println("IN");
} else {
System.out.println("OUT");
}
}
I thought maybe i've got some problem with the api key, but i didn't got any message refers to it
Sorry for my poor english :S

Android Facebook SDK authorize methods shows dialog every time

I'm writing an Android application that should upload photos to Facebook.
Everything works just fine except one thing. When I called the Facebook.authorize() method for the first time the Facebook dialog was shown with requested permissions and 'Allow'/'Don't Allow' buttons. That was OK. But when I run my app for the secong time I've got the same dialog, but with message that my application allowed already and suggestion to press OK button.
Is there a way to avoid this second dialog? Should I skip the authorize method in some conditions?
I tried to call the Facebook.isSessionValid() method before authorize method, but this did not help.
Here is my simplified code:
mFacebook = new Facebook(APPLICATION_ID);
mFacebookAsync = new AsyncFacebookRunner(mFacebook);
if (mFacebook.isSessionValid()) {
uploadPictureFile();
}
else {
mFacebook.authorize(this, new String[] {"publish_stream"}, new Facebook.DialogListener() {
#Override
public void onFacebookError(FacebookError e) {
Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
#Override
public void onError(DialogError e) {
Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook dialog error: " + e.getLocalizedMessage(), Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
#Override
public void onComplete(Bundle values) {
uploadPictureFile();
}
#Override
public void onCancel() {Toast.makeText(PhotoFeederFacebookSendActivity.this, "Facebook authorization cancelled.", Toast.LENGTH_LONG).show();
finishWithResultCode(RESULT_CANCELED);
}
});
}
And here is my onActivityResult method:
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
mFacebook.authorizeCallback(requestCode, resultCode, data);
}
Any help appreciated. Thanks.
You need to call mFacebook.setAccessToken("your token") before mFacebook.isSessionValid()
and you need to save the token to preference yourself
If you only intend to update status see my post here...
Android Facebook Graph API to update status

facebook login dialog when no internet

I have a simple problem (maybe) with my code... I have a facebook button that will open the login dialog for the user, which works fine. but if there is no internet it'll take forever and I don't know how to timeout it... I've put it in a 'try' block, but it still takes way too long
this is the code for it
try{
facebook.authorize(this,new String[] {"publish_stream", "read_stream", "offline_access"}, new DialogListener() {
#Override
public void onComplete(Bundle values) {}
#Override
public void onFacebookError(FacebookError error) {}
#Override
public void onError(DialogError e) {}
#Override
public void onCancel() {}
});
} catch(Exception e) {
e.printStackTrace();
}
any help will be highly appreciated
P.S. this applies for the post into facebook as well
Why not put in some logic to detect whether there is a network connection and if not, do something nice for your users like tell them you require one. Check out this answer for more info.
I just faced same issue, and you have 2 way to do:
Edit Util.java in facebook SDK, add 1 line like conn.setTimeout(xxx);
Upgrade to newest facebook SDK, now it have timeout mechanism.

Categories

Resources