android - 未安装应用程序时使用facebook shareDialog-奇怪的行为吗?

原文 标签 android facebook-graph-api facebook-sharer facebook-share publish-actions

facebook shareDialog when app is\isn't installed - weird behavior?

I'm using the ShareDialog of Facebook in order to share a printScreen image on facebook within my app.

When Facebook app is installed, it works alright.

When Facebook app isn't installed, it doesn't work. I see the "loading" screen and then it's disappeared and nothing happens. The share dialog object reaches onError callback with the FacebookException:

{FacebookGraphResponseException: (#200) Requires extended permission: publish_actions httpResponseCode: 403, facebookErrorCode: 200, facebookErrorType: OAuthException, message: (#200) Requires extended permission: publish_actions}

So do I really need "publish_actions" permission only for facebook web and not for facebook app? weird..

Facebook writes:

https://developers.facebook.com/docs/sharing/android

"If the Facebook app is not installed it will automatically fallback to the web-based dialog"

"Now the SDK automatically checks for the native Facebook app. If it isn't installed, the SDK switches people to their default browser and opens the Feed Dialog."

my code:

mShareDialog = new ShareDialog(mActivity);

    mShareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {}

        @Override
        public void onCancel() {}

        @Override
        public void onError(FacebookException error) {
            if (error != null) {
                showDialog("facebook app isn't installed");
            }
        }
    });

    if (ShareDialog.canShow(ShareLinkContent.class)) {

        // get a screenshot
        Bitmap image = getScreenshot();

        SharePhoto photo = new SharePhoto.Builder()
                .setBitmap(image)
                .setCaption(getResources().getString(R.string.shareBodyText))
                .build();

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

        mShareDialog.show(content);
    }

So why does it work when facebook app is installed without the "publish_actions" and doesn't work when facebook app isn't installed?

Answer

It's a requirement of the SharePhotoContent, you must have installed the native faceboook app in order to share photos.

From Facebook Docs

Photos

People can share photos from your app to Facebook with the Share Dialog or with a custom interface.

  • The photos must be less than 12MB in size
  • People need the native Facebook for Android app installed, version 7.0 or higher

翻译

我正在使用Facebook的ShareDialog,以便在我的应用程序中在facebook上共享printScreen图像。

安装Facebook应用程序后,它可以正常工作。

如果未安装Facebook应用,则它将无法正常工作。我看到“正在加载”屏幕,然后消失了,没有任何反应。
共享对话框对象通过FacebookException到达onError回调:

{FacebookGraphResponseException: (#200) Requires extended permission: publish_actions httpResponseCode: 403, facebookErrorCode: 200, facebookErrorType: OAuthException, message: (#200) Requires extended permission: publish_actions}


那么,我真的只需要对Facebook网站而不是对Facebook应用程序具有“ publish_actions”权限吗?奇怪的..

Facebook writes:


https://developers.facebook.com/docs/sharing/android

"If the Facebook app is not installed it will automatically fallback to the web-based dialog"

"Now the SDK automatically checks for the native Facebook app. If it isn't installed, the SDK switches people to their default browser and opens the Feed Dialog."


我的代码:

mShareDialog = new ShareDialog(mActivity);

    mShareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {}

        @Override
        public void onCancel() {}

        @Override
        public void onError(FacebookException error) {
            if (error != null) {
                showDialog("facebook app isn't installed");
            }
        }
    });

    if (ShareDialog.canShow(ShareLinkContent.class)) {

        // get a screenshot
        Bitmap image = getScreenshot();

        SharePhoto photo = new SharePhoto.Builder()
                .setBitmap(image)
                .setCaption(getResources().getString(R.string.shareBodyText))
                .build();

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

        mShareDialog.show(content);
    }


那么,为什么在没有安装“ publish_actions”的情况下安装Facebook应用程序却没有安装,而在没有安装Facebook应用程序的情况下却无法使用呢?
最佳答案
这是SharePhotoContent的要求,您必须已安装本机faceboook应用程序才能共享照片。

来自Facebook Docs


  相片
  
  人们可以使用“共享”将您的应用程序中的照片共享到Facebook
  对话框或带有自定义界面。
  
  
  照片的大小必须小于12MB
  人们需要安装适用于7.0或更高版本的Android应用程序的本地Facebook
相关推荐

android - 窗口小部件服务不会在尝试填充集合之前等待数据

android - Android MediaPlayer.getCurrentPosition()返回不正确的值

android - 使用先前的流ID攻击连接到XMPP服务器

android - 带有ExoPlayer的MPEG-TS H.264

android - J2V8和Stetho

android - 如何从React Native打开另一个应用程序?

android - 如何在Parallel Space中停止我的应用程序?

android - 实际在Android和iOS中央/外围设备上协商Bluetooth LE ATT MTU

c# - Xamarin中的大量内存使用

android - 浮动动作按钮意外锚重力变化