Android Facebook integration
العربية
български
català
中文
čeština
dansk
Nederlands
eesti
suomi
français
Deutsch
Ελληνικά
עברית
हिंदी
magyar
Bahasa Indonesia
italiano
日本語
한국어
latviešu
lietuvių
norsk
polski
Português
română
русский
slovenčina
slovenski
español
svenska
ไทย
Türkçe
українська
Tiếng Việt
I've got Facebook integration basically working in my app: the facebook dialog comes up and the user can select Allow or Don't Allow. However, I don't understand how the API works! I've got an Activity with this code:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "in oncreate facebookactivity");
facebook.authorize(this, new String[] {"publish_stream"}, new DialogListener() {
public void onComplete(Bundle values) {
Log.d(TAG, "facebook oncomplete with values " + values.toString());
}
public void onFacebookError(FacebookError error) {
Log.e(TAG, "there was a FacebookError authorising: " + error);
}
public void onError(DialogError e) {
Log.e(TAG, "there was a DialogError authorising: " + e);
}
public void onCancel() {
Log.d(TAG, "facebook auth was cancelled");
}
});
finish();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.d(TAG, "facebook onactivityresult with resultcode " + resultCode);
facebook.authorizeCallback(requestCode, resultCode, data);
finish();
}
And NONE of my debug statements except the "in oncreate facebookactivity" ever prints.
My question is: how do I know whether the user has pressed Allow or Don't Allow? Is there something in the values sent to onComplete? Or something in the data sent to onActivityResult? The reason I need to know is because I would like to store the user's selection in the prefs of my app.
Many thanks
Nina
Answer |
Only once you select Allow, FB begins to authorize your session, hence nothing happens until you select Allow. The DialogListener serves this purpose i.e. to capture what option the user selected. Because you haven't selected either choice your debug messages are not being logged.
The values parameter in the onComplete method contains your access token and your expiry time for that access token, once a user has selected Allow.
OnActivityResult is not related to this issue.