使用facebook sdk android共享图片时无需显示任何内容

时间:2015-10-30 00:37:21

标签: java android facebook

我正在尝试学习如何使用android和facebook SDK分享一个简单的图像tutorial

我已经在facebook开发者页面中配置了应用程序,其中包括App ID,开发密钥哈希和发布密钥哈希。

问题是,当我登录时,它出现在这个屏幕上: enter image description here 然后当我点击确定没有任何反应......

这是我的MainActivity:

public class MainActivity extends ActionBarActivity {

private CallbackManager callbackManager;
private LoginManager loginManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Get the release key hash in Debug.Log
    generateHash();

    // Initialize the facebook SDK
    FacebookSdk.sdkInitialize(getApplicationContext());

    callbackManager = CallbackManager.Factory.create();

    // If we want to publish something on facebook we need publish permission
    List<String> permissionNeeds = Arrays.asList("publish_actions");

    loginManager = LoginManager.getInstance();

    loginManager.logInWithPublishPermissions(this, permissionNeeds);

    loginManager.registerCallback(callbackManager, new FacebookCallback<LoginResult>()
    {
        @Override
        public void onSuccess(LoginResult loginResult)
        {
            sharePhotoToFacebook();
        }

        @Override
        public void onCancel()
        {
            System.out.println("onCancel");
        }

        @Override
        public void onError(FacebookException exception)
        {
            System.out.println("onError");
        }
    });
}

private void sharePhotoToFacebook(){
    Bitmap image = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    SharePhoto photo = new SharePhoto.Builder()
            .setBitmap(image)
            .setCaption("Give me my codez or I will ... you know, do that thing you don't like!")
            .build();

    SharePhotoContent content = new SharePhotoContent.Builder()
            .addPhoto(photo)
            .build();

    ShareApi.share(content, null);
}

继承我的AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET" />

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity android:name="com.facebook.FacebookActivity"
        android:theme="@android:style/Theme.Translucent.NoTitleBar"
        android:label="@string/app_name"/>
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id"/>

    <provider
        android:authorities="com.facebook.app.FacebookContentProvider1018821948180724"
        android:name="com.facebook.FacebookContentProvider"
        android:exported="true">
    </provider>

</application>

关于我做错了什么的提示?

提前致谢。

1 个答案:

答案 0 :(得分:0)

您是否已将Facebook ContentProvider添加到您的清单中?

<provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
          android:name="com.facebook.FacebookContentProvider"
          android:exported="true"/>

记住这些事情:
1.照片尺寸必须小于12MB 2.登录时需要询问publish_actions权限