I'm using sdk 3.7
My Android application doen't use FB authentication, but I have a share button.
On this button click, I trying to create a session and open a FB WebDialog, when I do that I'm getting dialog that asks me for publish permission and after that the Session doen't opened and I'm getting com.facebook.FacebookAuthorizationException: UnknownError: ApiException:The app must ask for a basic_info permission at install time.
I tried:
1. to add 'basic_info' permission.
2. to uninstall my app and the fb app and install again.
How solve this problem?
(see my code below)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
boolean isFacebookResponse =
Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
if (isFacebookResponse) {
}
}
@Override
public void onFacebookShareClick() {
checkFacebookLogin();
}
/**
* Login to FB if needed
*/
private void checkFacebookLogin() {
Session session = Session.getActiveSession();
try {
if (session == null || session.getState() != SessionState.OPENED) {
logInToFacebook();
} else {
publishFeedDialog();
}
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* login to facebook
*/
private void logInToFacebook() {
String app_id = getString(R.string.app_id);
Settings.addLoggingBehavior(LoggingBehavior.INCLUDE_ACCESS_TOKENS);
Session session = new Session.Builder(this)
.setApplicationId(app_id)
.build();
session.addCallback(this);
Session.setActiveSession(session);
List<String> PERMISSIONS = Arrays.asList("publish_actions");
// Login
if (!session.isOpened() && !session.isClosed()) {
session.openForPublish(new Session.OpenRequest(this)
.setPermissions(PERMISSIONS)
.setCallback(this));
} else {
Session.openActiveSession(this, true, this);
}
}
/**
* Disconnect from facebook
*/
public void logOut() {
Session session = Session.getActiveSession();
if (!session.isClosed()) {
session.closeAndClearTokenInformation();
}
}
@Override
public void call(Session session, SessionState state, Exception exception) {
if (state == SessionState.OPENED) {
publishFeedDialog();
}
if(exception !=null){
exception.printStackTrace();
}
}
private void publishFeedDialog() {
Bundle params = new Bundle();
params.putString("name", "test name");
params.putString("caption", "test caption");
params.putString("description", "test description");
params.putString("link", "test link");
params.putString("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/Images/iossdk_logo.png");
WebDialog feedDialog = (
new WebDialog.FeedDialogBuilder(this,
Session.getActiveSession(), params))
.setOnCompleteListener(new WebDialog.OnCompleteListener() {
@Override
public void onComplete(Bundle values, FacebookException error) {
if (error == null) {
// When the story is posted, echo the success
// and the post Id.
final String postId = values.getString("post_id");
if (postId != null) {
//DebugToast.show(getApplicationContext(), "Posted story, id: " + postId);
} else {
// User clicked the Cancel button
//DebugToast.show(getApplicationContext(), "Publish cancelled");
}
} else if (error instanceof FacebookOperationCanceledException) {
// User clicked the "x" button
//DebugToast.show(getApplicationContext(), "Publish cancelled");
} else {
// Generic, ex: network error
//DebugToast.show(getApplicationContext(), "Error posting story");
}
logOut();
}
})
.build();
feedDialog.show();
}