无法通过Facebook分享应用截图

时间:2017-07-23 18:08:42

标签: android facebook facebook-opengraph

我正在尝试使用开放图形api将应用程序生成的屏幕截图分享给Facebook。这是我的代码:

View rootView = ((DayOverviewActivity)context).getWindow().getDecorView().
                findViewById(android.R.id.content);
        //create bitmap
        SharePhoto photo = new SharePhoto.Builder()
                .setBitmap(getScreenshot(rootView))
                .setUserGenerated(true)
                .build();
        // Create an object
        ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
                .putString("og:type", "books.book")
                .putString("og:title", "A Game of Thrones")
                .putString("og:description", "In the frozen wastes to the north of Winterfell, sinister and supernatural forces are mustering.")
                .putString("books:isbn", "0-553-57340-3")
                .build();
        // Create an action
        ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
                .setActionType("books.reads")
                .putObject("book", object)
                .putPhoto("image", photo)
                .build();
        // Create the content
        ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
                .setPreviewPropertyName("book")
                .setAction(action)
                .build();
        shareDialog.show(content);

屏幕截图功能:

public static Bitmap getScreenShot(View view) {
        View screenView = view.getRootView();
        screenView.setDrawingCacheEnabled(true);
        Bitmap bitmap = Bitmap.createBitmap(screenView.getDrawingCache());
        screenView.setDrawingCacheEnabled(false);
        return bitmap;
    }

以下是我遇到的错误:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.net.Uri.toString()' on a null object reference
                                                                          at com.facebook.share.internal.ShareInternalUtility$8.toJSONObject(ShareInternalUtility.java:424)
                                                                          at com.facebook.share.internal.OpenGraphJSONUtility.toJSONValue(OpenGraphJSONUtility.java:101)
                                                                          at com.facebook.share.internal.OpenGraphJSONUtility.toJSONObject(OpenGraphJSONUtility.java:59)
                                                                          at com.facebook.share.internal.ShareInternalUtility.toJSONObjectForWeb(ShareInternalUtility.java:415)
                                                                          at com.facebook.share.internal.WebDialogParameters.create(WebDialogParameters.java:139)
                                                                          at com.facebook.share.widget.ShareDialog$WebShareHandler.createAppCall(ShareDialog.java:384)
                                                                          at com.facebook.share.widget.ShareDialog$WebShareHandler.createAppCall(ShareDialog.java:357)
                                                                          at com.facebook.internal.FacebookDialogBase.createAppCallForMode(FacebookDialogBase.java:215)
                                                                          at com.facebook.internal.FacebookDialogBase.showImpl(FacebookDialogBase.java:150)
                                                                          at com.facebook.internal.FacebookDialogBase.show(FacebookDialogBase.java:145)
                                                                          at com.jaribio.jaribio.OverView.WeekendStatisticsFragment.shareResults(WeekendStatisticsFragment.java:225)
                                                                          at com.jaribio.jaribio.OverView.WeekendStatisticsFragment.access$100(WeekendStatisticsFragment.java:47)
                                                                          at com.jaribio.jaribio.OverView.WeekendStatisticsFragment$1.onClick(WeekendStatisticsFragment.java:123)
                                                                          at android.view.View.performClick(View.java:5265)
                                                                          at android.view.View$PerformClick.run(View.java:21534)
                                                                          at android.os.Handler.handleCallback(Handler.java:815)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:104)
                                                                          at android.os.Looper.loop(Looper.java:207)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:5728)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)

问题似乎在于SharePhoto块,因为当我将其注释掉时,代码运行正常。我在我的清单文件中添加了ContentProvider详细信息。

0 个答案:

没有答案