1

所以我试图让 Facebook 的 Feed 对话框弹出,但是当我弹出它时它就会关闭,就像它失败或其他什么一样。顺便说一句,如果安装了他们的应用程序,我只会与 facebook 打交道。除非安装了它们,否则我不想与他们分享。

这是我要离开的地方:https ://developers.facebook.com/docs/howtos/androidsdk/3.0/feed-dialog/

与此集成一点用于授权和登录: https ://developers.facebook.com/docs/howtos/androidsdk/3.0/native-login/

这是我的代码:

private static final List<String> PERMISSIONS = Arrays.asList("publish_actions");

public void sendToFacebook()
{
if (session != null && session.isOpened()) {
    List<String> permissions = session.getPermissions();
    if (!isSubsetOf(PERMISSIONS, permissions)) {
        pendingPublishReauthorization = true;
        Session.NewPermissionsRequest newPermissionsRequest = new Session
                .NewPermissionsRequest(activity, PERMISSIONS);
        session.requestNewPublishPermissions(newPermissionsRequest);
        return;
    }
    final Bundle parameters = new Bundle();
    parameters.putString(NAME, app name);
    parameters.putString(LINK, info);
    parameters.putString(PICTURE, picture link);
    parameters.putString(CAPTION, "caption stuff");
    parameters.putString(DESCRIPTION, "description");

    activity.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            WebDialog feedDialog = (
                    new WebDialog.FeedDialogBuilder(activity,
                        Session.getActiveSession(),
                        parameters))
                    .setOnCompleteListener(new OnCompleteListener() {

                        @Override
                        public void onComplete(Bundle values,
                            FacebookException error) {
                            //do something
                        }

                    })
                    .build();
                feedDialog.show();
        }
    });

    }else{
        initFacebookEngine(); //inits or opens the session. 
    }
    }

    private boolean isSubsetOf(Collection<String> subset, Collection<String> superset) {
        for (String string : subset) {
            if (!superset.contains(string)) {
                return false;
            }
        }
        return true;
    }

    private void initFacebookEngine() {
    if(session == null){
        session = new Session.Builder(ctx).build();
    }
    if(!session.isOpened() || !session.isClosed()){

         session.openForPublish(new Session.OpenRequest(activity)
            .setPermissions(PERMISSIONS)
            .setCallback(callback));
    }else{
        Session.openActiveSession(activity, true, callback);
    }

我将方法称为 sendToFacebook。回调仅在调用时调用 sendToFacebook。该代码将执行身份验证和权限,但提要对话框不会显示其面孔。Facebook 会表现得好像它正在做某事,然后完成并返回我的应用程序。有谁知道发生了什么?

4

0 回答 0