我遇到了错误:
必须在AndroidManifest.xml中设置有效的Facebook应用ID或进行设置 通过在初始化sdk之前调用FacebookSdk.setApplicationId。
我的代码:
Manifest.xml
<uses-permission android:name="android.permission.INTERNET" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="1xxxxxxxxxxxxx"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:networkSecurityConfig="@xml/network_security_config"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".LoginActivity"
android:configChanges="orientation"
android:screenOrientation="portrait"
android:label="@string/title_activity_login">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
<category android:name="android.intent.category.LAUNCHER"></category>
</intent-filter>
</activity>
<activity android:name="com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label="@string/app_name" />
<activity
android:name="com.facebook.CustomTabActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="@string/fb_login_protocol_scheme" />
</intent-filter>
</activity>
</application>
MainActivity.java
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
context = this;
FacebookSdk.sdkInitialize(getApplicationContext());
AppEventsLogger.activateApp(this);
fabFB = findViewById(R.id.fabFb);
fabFB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ShareDialog shareDialog;
FacebookSdk.sdkInitialize(context);
shareDialog = new ShareDialog(context);
ShareLinkContent linkContent = new ShareLinkContent.Builder()
.setContentTitle("Title")
.setContentDescription("Description")
.setContentUrl(Uri.parse("https://mywebsite.com")).build();
shareDialog.show(linkContent);
}
});
AppId
文件中有正确的Manifest
,但仍然出现该错误。
我不想使用Facebook登录名,而只是分享页面。
我在做什么错了?