使用FacebookDialog在Facebook上发布照片

时间:2015-01-16 10:41:10

标签: android facebook facebook-graph-api

我在getApplicationContext()处获得空指针异常。这是我的代码。

 if (FacebookDialog.canPresentShareDialog
        (getApplicationContext(),
                FacebookDialog.ShareDialogFeature.PHOTOS)) {
    // Publish the post using the Photo Share Dialog
    RelativeLayout views = (RelativeLayout) findViewById(R.id.viewlayout);
    views.setDrawingCacheEnabled(true);
    views.buildDrawingCache();
    Bitmap img = views.getDrawingCache();
    ArrayList<Bitmap> list = new ArrayList<Bitmap>();
    list.add(img);
    FacebookDialog shareDialog = new FacebookDialog.PhotoShareDialogBuilder(this)
            .addPhotos(list)
            .build();
    uiHelper.trackPendingDialogCall(shareDialog.present());
} else {
    Toast.makeText(getApplicationContext(), "no", Toast.LENGTH_LONG).show();
}

}

我已检查过facebook是否已安装。它回归真实。所以很明显FacebookDialog.canPresentShareDialog不是概率。尝试了这个,背景和一切。

这是我的LOg:

 java.lang.NullPointerException
                at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:883)
                at com.facebook.internal.Utility.getDialogFeatureConfig(Utility.java:717)
                at com.facebook.widget.FacebookDialog.getVersionSpecForFeature(FacebookDialog.java:498)
                at com.facebook.widget.FacebookDialog.getVersionSpecForFeatures(FacebookDialog.java:489)
                at com.facebook.widget.FacebookDialog.handleCanPresent(FacebookDialog.java:465)
                at com.facebook.widget.FacebookDialog.canPresentShareDialog(FacebookDialog.java:411)
                at com.racebuddy2.Results.postOnFacebook(Results.java:196)
                at com.racebuddy2.Results.access$000(Results.java:34)
                at com.racebuddy2.Results$2.onClick(Results.java:82)
                at android.view.View.performClick(View.java:4456)
                at android.view.View$PerformClick.run(View.java:18465)
                at android.os.Handler.handleCallback(Handler.java:733)
                at android.os.Handler.dispatchMessage(Handler.java:95)
                at android.os.Looper.loop(Looper.java:136)
                at android.app.ActivityThread.main(ActivityThread.java:5086)
                at java.lang.reflect.Method.invokeNative(Native Method)
                at java.lang.reflect.Method.invoke(Method.java:515)
                at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
                at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
                at dalvik.system.NativeStart.main(Native Method)

M使用facebook sdk 3.22.0作为gradle给出了。我该怎么办?哪里是错误。 :(

1 个答案:

答案 0 :(得分:1)

我得到了我的工作。似乎https://stackoverflow.com/a/19169776/642185就是答案。

我能够登录,因为我将facebook app ID作为代码中的字符串,但我需要在元数据中使这部分工作。