FB sdk, requestNewPublishPermissions() doesn't call any callback

萝らか妹 提交于 2019-12-06 15:59:38

I finally figured this out. As many people said, it was an onActivityResult() problem, but quite vicious.

When Log In, the FacebookLoginFragment.onSessionStateChange() was called succefully, whereas the NewsFragment.onSessionStateChange() was never called during the persmission process.

After several tests, I assume this was due to a static and dynamic binding. My FacebookLoginfragment is directy referenced in the xml (static), whereas my NewsFragment is added dynamically in the source code. Consequently, the Activity which contains both fragments was only sending the onActivityResult signal to the FacebokLoginFragment. Therefore, the NewsFragment.onActivityResult() which is necessary to trigger the callback was never called.

Overriding the Activity.onActivityResult() gives me the expected behavior :

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    getSupportFragmentManager().findFragmentById(R.id.my_fragment_frame).onActivityResult(requestCode, resultCode, data);
} 

Yes, there indeed seems to still be a bug around callbacks and new permissions requests.

As a temporary work around, you can call:

session.addCallback(yourCallback);

just before you call session.requestNewPublishPermissions.

Note that this callback will now receive all future state changes on your session. If that's not what you want, you can always call session.removeCallback(yourCallback) after you do the publish.

Even if you add the callback as Ming said, you may have an issue.

See this bug: https://developers.facebook.com/bugs/130681460449340

It looks like there is a proposed solution/workaround in the comments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!