问题
Following THIS I'm using facebook sdk in my android application and for test I've added below code to my MainActivity:
CallbackManager callbackManager;
ShareDialog shareDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
setContentView(R.layout.activity_main);
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
if (ShareDialog.canShow(ShareLinkContent.class)) {
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Hello Facebook")
.setContentDescription(
"The 'Hello Facebook' sample showcases simple Facebook integration")
.setContentUrl(Uri.parse("http://developers.facebook.com/android"))
.build();
shareDialog.show(linkContent);
}
}
and I've added the following steps in my manifest:
<uses-permission android:name="android.permission.INTERNET"/>
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
<provider android:authorities="com.facebook.app.FacebookContentProvider950310748347640"
android:name="com.facebook.FacebookContentProvider"
android:exported="true" />
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:label="@string/app_name" />
and when I test the shareDialog pops up and suddenly it closes itself.
回答1:
You need to make your app "Public".
Go to the "Status and Review" section in your app settings, and turn on the option "Do you want to make this app and all its live features available to the general public?"
回答2:
You need to specify a Mode on the show() method. Between FEED,
NATIVE, WEB and AUTOMATIC
the most convenient one is the last one (AUTOMATIC) because it collects data straight from Facebook app so you don't have to log in, but some times it closes unexpectandly..
Generally here is what i thing:
- FFED: 1)Works through Google Chrome, 2)old design 3)need to log in
- NATIVE: 1)Posts using the facebook app, no need for extra login
- WEB: Similar to FEED but with different UI
AUTOMATIC: (Sometimes on start it closes immediately..) 1)uses only facebook app 2) no need to re-login 3)shares like any other share Take a better look here:https://developers.facebook.com/docs/reference/android/current/class/ShareDialog.Mode/ So i would suggest WEB, cause it works always:
shareDialog.show(linkContent, ShareDialog.Mode.WEB );
回答3:
The problem was with the phone I was testing the application on, as it seems you have to be logged into facebook application using the Facebook account who is marked as developer which your application is registered under, then it will work as it supposed to and I assume for later use when you use the release ssh key it will work on any device with any account.
回答4:
This is due to the fact that the app is not live and available to public. For that , you first need to have Privacy Policy link. Facebook recently , update their policy which requires almost every app to have their privacy policy link set up in the dash board. You can generate one for free using https://www.iubenda.com/privacy-policy-generator . Hope it helps!
回答5:
My situation was different. There were 3 reasons why I experienced this issue:
App FB App Id was invalid (Had two facebook apps and I accidentally set the wrong app ID).
Image URL was invalid / had a self signed certificate issue :
og:image
. I changed fromhttps
tohttp
and it worked.Web Url was invalid :
og:url
. The url started with www where as the correct way ishttp
orhttps
followed bywww
Hope this helps someone.
回答6:
This can happen when you're logged in to facebook with a test user created for a different app.
来源:https://stackoverflow.com/questions/30153337/facebook-android-sharedialog-closes-after-opening