sromku / android-simple-facebook

[Deprecated] Simple Facebook SDK for Android
Other
878 stars 349 forks source link

Not showing the fb dialog which used to grant the public_action permisson for publishing posts #303

Open ghost opened 9 years ago

ghost commented 9 years ago

MY Code :

In Application class SimpleFacebookConfiguration configuration = new SimpleFacebookConfiguration.Builder() .setAppId(getString(R.string.fb_app_id)) .setNamespace(FACEBOOK_NAMESPACE).setPermissions(PERMISSIONS) .setAskForAllPermissionsAtOnce(false) .build(); SimpleFacebook.setConfiguration(configuration);

In My Activity private SimpleFacebook mSimpleFacebook;

@Override
protected void onResume()
{
    super.onResume();
    try
    {
        mSimpleFacebook = SimpleFacebook.getInstance(this);
    }
    catch (Exception e)
    {
        Utils.logError(e);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);
    try
    {
        if (mSimpleFacebook != null)
        {
            mSimpleFacebook.onActivityResult(this, requestCode, resultCode,
                    data);
        }
    }
    catch (Exception e)
    {
        Utils.logError(e);
    }
}

In My fragment

     private void loginAndPublish()
{
    SimpleFacebook instance = SimpleFacebook.getInstance();

    instance.login(new OnLoginListener()
    {
        @Override
        public void onFail(String reason)
        {

        }

        @Override
        public void onException(Throwable throwable)
        {

        }

        @Override
        public void onThinking()
        {

        }

        @Override
        public void onNotAcceptingPermissions(Type type)
        {

        }

        @Override
        public void onLogin()
        {
            requestNewPermission();
        }
    });
}

private void requestNewPermission()
{
    SimpleFacebook instance = SimpleFacebook.getInstance();

    instance.requestNewPermissions(new Permission[]{Permission.PUBLISH_ACTION}, true,
            new OnNewPermissionsListener()
            {
                @Override
                public void onFail(String reason)
                {
                }

                @Override
                public void onException(Throwable throwable)
                {

                }

                @Override
                public void onThinking()
                {

                }

                @Override
                public void onSuccess(String accessToken,
                        List<Permission> declinedPermissions)
                {
                    publishOnFb();
                }

                @Override
                public void onNotAcceptingPermissions(Type type)
                {

                }
            });
}

private void publishOnFb()
{
    SimpleFacebook instance = SimpleFacebook.getInstance();

    PostModel post = getPost();
    String postText = post.toString(getActivity());
    String imageUrl = post.getImage_url();
    Feed feed = new Feed.Builder().setMessage(postText).setName("Yafda7to")
            .setCaption(postText).setDescription(postText)
            .setPicture(imageUrl).build();

    instance.publish(feed, new OnPublishListener()
    {
        @Override
        public void onFail(String reason)
        {

// Fails here with "Publish permissions: '[publish_actions]' weren't accepted by user" without even
// showing a dialog for granting the permission from the user }

        @Override
        public void onException(Throwable throwable)
        {

        }

        @Override
        public void onComplete(String postId)
        {

        }
    });

}

iceteahh commented 8 years ago

I have same problem here. Some one please help.