Android-Facebook SDK:无法共享照片,对话框无法显示

Android-Facebook SDK:无法共享照片,对话框无法显示,第1张

概述这是我第一次使用 Android-Facebook SDK.我想发布一个位图,但我继续收到这条消息: Warning: Error: com.facebook.FacebookException: Failed to copy image. 我可以发布简单的链接,但不能发布带照片的链接. 我该怎么解决这个问题?另外,我注意到的一件事是没有调用StatusCallback.call(). publi 这是我第一次使用 Android-Facebook SDK.我想发布一个位图,但我继续收到这条消息:
Warning: Error: com.facebook.FacebookException: Failed to copy image.

我可以发布简单的链接,但不能发布带照片的链接.

我该怎么解决这个问题?另外,我注意到的一件事是没有调用StatusCallback.call().

public abstract class FacebookReadyBaseActivity extends Activity {    private static final String TAG = "FacebookReadyBaseActivity";    private UilifecycleHelper uiHelper;    protected PendingAction pendingAction = PendingAction.NONE;    private static final String PERMISSION = "publish_actions";    protected boolean canPresentShareDialogWithPhotos;    private boolean canPresentShareDialog;    private GraphUser user;    private GraPHPlace place;    private List<GraphUser> Tags;    protected Bitmap pendingBitmap;    protected enum PendingAction {        NONE,POST_PHOTO,POST_STATUS_UPDATE    }    private Session.StatusCallback callback = new Session.StatusCallback() {        @OverrIDe        public voID call(Session session,SessionState state,Exception exception) {            onSessionStateChange(session,state,exception);        }    };    @OverrIDe    protected voID onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        uiHelper = new UilifecycleHelper(this,callback);        uiHelper.onCreate(savedInstanceState);        canPresentShareDialog = FacebookDialog.canPresentShareDialog(this,FacebookDialog.ShareDialogFeature.SHARE_DIALOG);        canPresentShareDialogWithPhotos = FacebookDialog.canPresentShareDialog(                this,FacebookDialog.ShareDialogFeature.PHOTOS);    }    @OverrIDe    protected voID onActivityResult(int requestCode,int resultCode,Intent data) {        super.onActivityResult(requestCode,resultCode,data);        uiHelper.onActivityResult(requestCode,data,new FacebookDialog.Callback() {                    @OverrIDe                    public voID onError(FacebookDialog.PendingCall pendingCall,Exception error,Bundle data) {                        Log.e(TAG,String.format("Error: %s",error.toString()));                    }                    @OverrIDe                    public voID onComplete(                            FacebookDialog.PendingCall pendingCall,Bundle data) {                        Log.i(TAG,"Success!");                    }                });    }    @OverrIDe    protected voID onResume() {        super.onResume();        uiHelper.onResume();    }    @OverrIDe    protected voID onSaveInstanceState(Bundle outState) {        super.onSaveInstanceState(outState);        uiHelper.onSaveInstanceState(outState);    }    @OverrIDe    public voID onPause() {        super.onPause();        uiHelper.onPause();    }    @OverrIDe    public voID onDestroy() {        super.onDestroy();        uiHelper.onDestroy();    }    protected UilifecycleHelper getFacebookUiHelper() {        return uiHelper;    }    protected voID performpublish(PendingAction action,boolean allowNoSession) {        Session session = Session.getActiveSession();        if (session != null) {            pendingAction = action;            if (hasPublishPermission()) {                // We can do the action right away.                handlePendingAction();                return;            } else if (session.isOpened()) {                // We need to get new permissions,then complete the action when                // we get called back.                session.requestNewPublishPermissions(new Session.NewPermissionsRequest(                        this,PERMISSION));                return;            }        }        if (allowNoSession) {            pendingAction = action;            handlePendingAction();        }    }    private boolean hasPublishPermission() {        Session session = Session.getActiveSession();        return session != null                && session.getPermissions().contains("publish_actions");    }    @SuppressWarnings("incomplete-switch")    private voID handlePendingAction() {        PendingAction prevIoUslyPendingAction = pendingAction;        // These actions may re-set pendingAction if they are still pending,but        // we assume they        // will succeed.        pendingAction = PendingAction.NONE;        switch (prevIoUslyPendingAction) {        case POST_PHOTO:            postPhoto();            break;        case POST_STATUS_UPDATE:            poststatusUpdate();            break;        }    }    private voID postPhoto() {        if (canPresentShareDialogWithPhotos) {            FacebookDialog shareDialog = createShareDialogBuilderForPhoto(                    pendingBitmap).build();            uiHelper.trackPendingDialogCall(shareDialog.present());        } else if (hasPublishPermission()) {            Request request = Request.newUploadPhotoRequest(                    Session.getActiveSession(),pendingBitmap,new Request.Callback() {                        @OverrIDe                        public voID onCompleted(Response response) {                            InfoDialog.newInstance(                                    FacebookReadyBaseActivity.this,"Done","Photo share finished.",null).show();                        }                    });            request.executeAsync();        } else {            pendingAction = PendingAction.POST_PHOTO;        }    }    private voID poststatusUpdate() {        if (canPresentShareDialog) {            FacebookDialog shareDialog = createShareDialogBuilderForlink()                    .build();            uiHelper.trackPendingDialogCall(shareDialog.present());        } else if (user != null && hasPublishPermission()) {            // Todo fixme            final String message = "Status update finished.";            Request request = Request.newStatusUpdateRequest(                    Session.getActiveSession(),message,place,Tags,new Request.Callback() {                        @OverrIDe                        public voID onCompleted(Response response) {                            InfoDialog.newInstance(                                    FacebookReadyBaseActivity.this,null).show();                        }                    });            request.executeAsync();        } else {            pendingAction = PendingAction.POST_STATUS_UPDATE;        }    }    private FacebookDialog.PhotoShareDialogBuilder createShareDialogBuilderForPhoto(            Bitmap... photos) {        return new FacebookDialog.PhotoShareDialogBuilder(this)                .addPhotos(Arrays.asList(photos));    }    private FacebookDialog.ShareDialogBuilder createShareDialogBuilderForlink() {        return new FacebookDialog.ShareDialogBuilder(this)                .setname("Hello Facebook")                .setDescription(                        "The 'Hello Facebook' sample application showcases simple Facebook integration")                .setlink("http://developers.facebook.com/androID");    }    private voID onSessionStateChange(Session session,Exception exception) {        if (pendingAction != PendingAction.NONE                && (exception instanceof FacebookOperationCanceledException || exception instanceof FacebookAuthorizationException)) {            InfoDialog.newInstance(FacebookReadyBaseActivity.this,"Failed","Not granted.",null).show();            pendingAction = PendingAction.NONE;        } else if (state == SessionState.OPENED_TOKEN_UPDATED) {            handlePendingAction();        }    }}
解决方法 终于搞定了!

在提供的HelloFacebookSample项目中,我在清单中看到了这个:

<provIDer androID:authoritIEs="com.facebook.app.NativeAppCallContentProvIDer355198514515820"                  androID:name="com.facebook.NativeAppCallContentProvIDer"                  androID:exported="true"/>

我只是使用自己的Facebook应用程序ID更改了数字部分.不知道为什么我没有在文档中看到这一点.

编辑
之后发现:https://developers.facebook.com/docs/reference/android/current/class/NativeAppCallContentProvider/

总结

以上是内存溢出为你收集整理的Android-Facebook SDK:无法共享照片,对话框无法显示全部内容,希望文章能够帮你解决Android-Facebook SDK:无法共享照片,对话框无法显示所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1134716.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存