Facebook publish permission

143 views
Skip to first unread message

Fabrizio Grassi

unread,
Mar 20, 2015, 7:44:01 PM3/20/15
to codenameone...@googlegroups.com
Hi all,
I just published my app on both App Store and Google Play but I'm waiting to telling it to everyone because I have an issue with Facebook that I want to solve: status feeds are not published even after login is successful. (the app has been approved by Facebook team for the publish permission)

Trying to understand it by myself, this should happens because my app never asks for the publish permission...
Supposing that this is true, I saw two methods in the FacebookConnect class:
hasPublishPermissions() and askPublishPermissions() which should solve the case but as I understand, these can be used only in newer devices and only if they have the Facebook app installed; all the other cases shuld rely on the FacebookAccess class but I don't see similar methods in it.

Could somebody makes this a little it clearer?


Shai Almog

unread,
Mar 21, 2015, 12:59:04 AM3/21/15
to codenameone...@googlegroups.com
Hi,
publishing to Facebook will only work on iOS/Android devices. I don't think you need to have the Facebook app installed but you need the native facebook SDK which only these platforms have. See: http://www.codenameone.com/blog/facebook-publish-android-localization.html

Fabrizio Grassi

unread,
Mar 21, 2015, 7:00:53 AM3/21/15
to codenameone...@googlegroups.com
hi shai,
just to know if I understand well:
I should always use FacebookConnect on iOS and Android.
Facebook SDK is an api that can be installed in Xcode or Eclipse and it does not depend on the device you are going to install the app on (Android from 2.3 to 4.4 and iOS from 6 to 8).

Do you think I understood?

Also, hasPublishPermissions() is a net command that asks to Facebook which permissions are enabled for the app and check the publish one? Can I use it to conditionally call the askPublishPermissions() (I removed a block in my code because it was always calling that method but I'm going to try again...) ?

Fabrizio Grassi

unread,
Mar 21, 2015, 8:31:47 AM3/21/15
to codenameone...@googlegroups.com
I tried to implement the publish permission issue but something doesn't work.
Here is the source of the command
private final Command share = new Command("Share", null) {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if (hasFacebookSDK) {
                if (! fc.hasPublishPermissions()) {
                    fc.askPublishPermissions(new LoginCallback() {
                        @Override
                        public void loginSuccessful() {
                            try {
                                fa.postOnWall(userId, textToShare.getText(), IJobClock.getMainform().getInfoAL());
                            } catch (IOException ex) {
                                Dialog.show("error", "error", "ok", null);
                            }
                            IJobClock.getInstance().setCurrent(IJobClock.popForm());
                            IJobClock.getInstance().getCurrent().showBack();
                        }

                        @Override
                        public void loginFailed(String message) {

                        }
                    });
                    return;
                }

                try {
                    fa.postOnWall(userId, textToShare.getText(), IJobClock.getMainform().getInfoAL());
                } catch (IOException ex) {
                    Dialog.show("error", "error", "ok", null);
                }
                IJobClock.getInstance().setCurrent(IJobClock.popForm());
                IJobClock.getInstance().getCurrent().showBack();
            } else {
                //Nothing to do?
            }
            
        }
    };
It seems that hasPublishPermissions() never returns "true" because the app always ask for this permission and always shows safari with a page in which Facebook says that this permission has just been given.
I also have other problems because returning back from safari very often leads to app restart and so the callback never execute.

Shai Almog

unread,
Mar 21, 2015, 11:28:44 AM3/21/15
to codenameone...@googlegroups.com
Publish permission will exist in the login callback and allow you to post there. Facebook recently blocked all publish operations without this API and that's only available in the native SDK login.
The code looks fine to me but Chen is a bigger Facebook expert and might have more informed feedback.

Chen Fishbein

unread,
Mar 21, 2015, 12:42:36 PM3/21/15
to codenameone...@googlegroups.com
Hi,
Not sure why the hasPublishPermissions won't return true after you granted the permission you can store a local flag that you got the permission and check against that, maybe it's because the facebook app is not installed and it uses the browser instead of the app



Fabrizio Grassi

unread,
Mar 21, 2015, 2:56:08 PM3/21/15
to codenameone...@googlegroups.com
Hi chen,
for the truth, on iOS I have Fb app installed.
On Android 4.4 I tried with and without Fb app installed and nothing changed BUT here the behavior is different: it seems that hasPublishPermissions() always returns true because it never asks me about permissions, even if I remove the app from my Fb preferences, and it behave like if it posted but when I check, nothing has been posted.
could you give it a try?


On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:

Fabrizio Grassi

unread,
Mar 24, 2015, 8:15:05 AM3/24/15
to codenameone...@googlegroups.com
Hi Chen,
Are there some news?

Fabrizio Grassi

unread,
Mar 27, 2015, 3:12:10 AM3/27/15
to codenameone...@googlegroups.com
Is there somebody who have experience with Facebook and can help me?

Shai Almog

unread,
Mar 27, 2015, 12:43:10 PM3/27/15
to codenameone...@googlegroups.com
This just worked relatively simply for most use cases, do you have a small test case that doesn't work?

Fabrizio Grassi

unread,
Mar 27, 2015, 1:33:04 PM3/27/15
to codenameone...@googlegroups.com
the code I posted above do not work for me on both android and iOS and seems to have different behavior on android than on iOS.


On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:

Chen Fishbein

unread,
Mar 29, 2015, 6:13:57 AM3/29/15
to codenameone...@googlegroups.com
Hi,
Not sure what fails here, I have tested with my app and it works.
How are you loggin in? are you using the single sign on? or maybe the web Form?

Fabrizio Grassi

unread,
Mar 29, 2015, 7:06:40 AM3/29/15
to codenameone...@googlegroups.com
On iOS I always get a safari form, so I think the web mode is selected both for login and permissions request. On Android nothing appear for permissions, for login I have to check because I don't remember...


On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:

Chen Fishbein

unread,
Mar 29, 2015, 10:27:57 AM3/29/15
to codenameone...@googlegroups.com
You need the single sign on to kick in - http://www.codenameone.com/blog/using-the-new-facebook-api.html

Fabrizio Grassi

unread,
Mar 29, 2015, 7:03:12 PM3/29/15
to codenameone...@googlegroups.com
Hi chen,
thanks for the reply. 
I don't understand if FacebookConnect replaces FacebookAccess or they work together. If the first case is true I'll remove all the FacebookAccess related code to try to get a clearer view but I have some doubts regarding all the parameters to set in FacebookAccess that disappear in FacebookConnect: is it possible that they are not needed anymore? 
Also, the token received by FacebookConnect.login()  must be saved or the api does it automatically?
just because I always get a safari view, what should I really expect as login view?


On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:

Chen Fishbein

unread,
Mar 30, 2015, 3:19:37 AM3/30/15
to codenameone...@googlegroups.com
Hi,
They work together, you should preform the login with the FacebookConnect it will automatically sets the token in the FacebookAccess.
The login experience should just flow without showing a login page since you are already logged in via the facebook app - take a look here - https://play.google.com/store/apps/details?id=il.co.fooxia.apps.travel2gether

(I still think we need to merge and improve the facebook integration, I will put this in my queue..)


Fabrizio Grassi

unread,
Mar 30, 2015, 7:16:39 AM3/30/15
to codenameone...@googlegroups.com
Hi Chen, I just installed travel2gether: login worked without asking me anything (this is different from what I get from my app) but I tried to publish a post on Facebook and after it asked me for permissions I posted a text but nothing really appeared on Facebook!

Could you try my app to see what is wrong from your point of view? Also to understand why I get different behaviors between Android and iOS (with the same code)?

Fabrizio Grassi

unread,
Mar 30, 2015, 12:20:02 PM3/30/15
to codenameone...@googlegroups.com
My app is iJobClock, you can find it in app store and play.

Fabrizio Grassi

unread,
Mar 30, 2015, 12:20:03 PM3/30/15
to codenameone...@googlegroups.com

Fabrizio Grassi

unread,
Apr 1, 2015, 1:32:18 PM4/1/15
to codenameone...@googlegroups.com
I just put a label on the bottom of the form to see some debug info and set a conditional text based on hasPublishPermissions(): it always display "have publish permission" even if I just removed iJobClock from my Facebook app (in my account preferences).

On the other side, iOS always shows me the safari view which says that i just allowed my app to publish for me and when I tap "ok" my app restart. the only time it didn't restart, the debug label show "permission NOT allowed".

here is the code
private final Command share = new Command("Share", null) {
        @Override
        public void actionPerformed(ActionEvent ae) {
            //if (/*hasFacebookSDK*/FacebookConnect.getInstance().isFacebookSDKSupported()) {
                Boolean temp = (Boolean) Storage.getInstance().readObject("canPublish");
                boolean canPublish = false;
                if (temp != null && (temp)) {
                    canPublish = true;
                }
                if ((! FacebookConnect.getInstance().hasPublishPermissions())) {
                //if (!canPublish) {
                    debug.setText("No publish permission");
                    FacebookConnect.getInstance().askPublishPermissions(new LoginCallback() {
                        @Override
                        public void loginSuccessful() {
                            Storage.getInstance().writeObject("canPublish", new Boolean(true));
                            try {
                                debug.setText("permission allowed");
                                String pre = Util.getIgnorCharsWhileEncoding();
                                Util.setIgnorCharsWhileEncoding(ignoreCharsWhenEncoding);
                                FaceBookAccess.getInstance().postOnWall(userId, textToShare.getText(), IJobClock.getMainform().getInfoAL());
                                Util.setIgnorCharsWhileEncoding(pre);
                            } catch (IOException ex) {
                                Dialog.show("error", "error", "ok", null);
                            }
                            IJobClock.getInstance().setCurrent(IJobClock.popForm());
                            IJobClock.getInstance().getCurrent().showBack();
                        }

                        @Override
                        public void loginFailed(String message) {
                            debug.setText("permission NOT allowed");
                        }
                    });
                    return;
                }

                debug.setText("have publish permission");
                try {
                    String pre = Util.getIgnorCharsWhileEncoding();
                    Util.setIgnorCharsWhileEncoding(ignoreCharsWhenEncoding);
                    FaceBookAccess.getInstance().postOnWall(userId, textToShare.getText(), IJobClock.getMainform().getInfoAL());
                    Util.setIgnorCharsWhileEncoding(pre);
                } catch (IOException ex) {
                    Dialog.show("error", "error", "ok", null);
                }
                IJobClock.getInstance().setCurrent(IJobClock.popForm());
                IJobClock.getInstance().getCurrent().showBack();
            /*} else {
                new Thread(){
                    @Override
                    public void run(){
                        Dialog.show("error", "Can't post without Facebook app, try again after installing it.", "ok", null);
                    }
                }.start();
        
            }*/
            /*try {
             String pre = Util.getIgnorCharsWhileEncoding();
             Util.setIgnorCharsWhileEncoding(ignoreCharsWhenEncoding);
             fa.postOnWall(userId, textToShare.getText(), IJobClock.getMainform().getInfoAL());
             Util.setIgnorCharsWhileEncoding(pre);
             } catch (IOException ex) {
             Dialog.show("error", "error", "ok", null);
             }
             IJobClock.getInstance().setCurrent(IJobClock.popForm());
             IJobClock.getInstance().getCurrent().showBack();*/
            /*Display.getInstance().callSeriallyAndWait(new Runnable() {
            
             @Override
             public void run() {
             IJobClock.getInstance().getCurrent().showBack();
             }
             });*/
        }
    };






On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:

Fabrizio Grassi

unread,
Apr 9, 2015, 7:16:10 AM4/9/15
to codenameone...@googlegroups.com
I have some news:
_ if I use directly postOnWall(id, text, actionListener) without the conditional hasPublishPermissions() I can post from iOS 6 while Android 4.4 throws an IOException with a message as 400: Bad Request.
_ askPublishPermissions(actionListener) actually doesn't do anything on android.



On Saturday, March 21, 2015 at 12:44:01 AM UTC+1, Fabrizio Grassi wrote:
Reply all
Reply to author
Forward
0 new messages