Android Facebook api 3.7- ApiException:The app must ask for a basic_info permission at install time -


i'm using sdk 3.7
android application doen't use fb authentication, have share button.

on button click, trying create session , open fb webdialog, when i'm getting dialog asks me publish permission , after session doen't opened , i'm getting com.facebook.facebookauthorizationexception: unknownerror: apiexception:the app must ask basic_info permission @ install time.

i tried:
1. add 'basic_info' permission. 2. uninstall app , fb app , install again.

how solve problem?
(see code below)

    @override         public void onactivityresult(int requestcode, int resultcode, intent data) {             super.onactivityresult(requestcode, resultcode, data);              boolean isfacebookresponse =                     session.getactivesession().onactivityresult(this, requestcode, resultcode, data);             if (isfacebookresponse) {              }         }          @override         public void onfacebookshareclick() {             checkfacebooklogin();         }  /**      * login fb if needed      */     private void checkfacebooklogin() {         session session = session.getactivesession();         try {             if (session == null || session.getstate() != sessionstate.opened) {                 logintofacebook();             } else {                 publishfeeddialog();             }         } catch (exception e) {             e.printstacktrace();         }     }      /**      * login facebook      */     private void logintofacebook() {         string app_id = getstring(r.string.app_id);          settings.addloggingbehavior(loggingbehavior.include_access_tokens);          session session = new session.builder(this)                 .setapplicationid(app_id)                 .build();         session.addcallback(this);         session.setactivesession(session);          list<string> permissions = arrays.aslist("publish_actions");          // login         if (!session.isopened() && !session.isclosed()) {             session.openforpublish(new session.openrequest(this)                     .setpermissions(permissions)                     .setcallback(this));         } else {             session.openactivesession(this, true, this);         }     }      /**      * disconnect facebook      */     public void logout() {         session session = session.getactivesession();         if (!session.isclosed()) {             session.closeandcleartokeninformation();         }     }      @override     public void call(session session, sessionstate state, exception exception) {         if (state == sessionstate.opened) {             publishfeeddialog();         }          if(exception !=null){             exception.printstacktrace();         }     }      private void publishfeeddialog() {         bundle params = new bundle();         params.putstring("name", "test name");         params.putstring("caption", "test caption");         params.putstring("description", "test description");         params.putstring("link", "test link");         params.putstring("picture", "https://raw.github.com/fbsamples/ios-3.x-howtos/master/images/iossdk_logo.png");          webdialog feeddialog = (                 new webdialog.feeddialogbuilder(this,                         session.getactivesession(), params))                 .setoncompletelistener(new webdialog.oncompletelistener() {                      @override                     public void oncomplete(bundle values, facebookexception error) {                         if (error == null) {                             // when story posted, echo success                             // , post id.                             final string postid = values.getstring("post_id");                             if (postid != null) {                                 //debugtoast.show(getapplicationcontext(), "posted story, id: " + postid);                             } else {                                 // user clicked cancel button                                 //debugtoast.show(getapplicationcontext(), "publish cancelled");                             }                         } else if (error instanceof facebookoperationcanceledexception) {                             // user clicked "x" button                             //debugtoast.show(getapplicationcontext(), "publish cancelled");                         } else {                             // generic, ex: network error                             //debugtoast.show(getapplicationcontext(), "error posting story");                         }                          logout();                     }                 })                 .build();         feeddialog.show();     } 

i'm not sure, didn't build project fb api, not yet try you. far can read, need separate request of read , publish permissions.

according fb api docs:

apps should separate request of read , publish permissions. plan app around requesting bare minimum of read permissions @ initial login , then publish permissions when person needs them.

so, code might be:

/*  * login facebook  */ private void logintofacebook() {     //...     if (!session.isopened() && !session.isclosed()) {         session.openforread(new session.openrequest(this)                 .setpermissions(arrays.aslist("basic_info"))                 .setcallback(this));     } else {         session.openactivesession(this, true, this);     } }  /*  * set publish_actions permission here  */ private void publishfeeddialog() {     session session = session.getactivesession();     // check session     if (session != null){         // create new permission         session.newpermissionsrequest newpermissionsrequest = new session                 .newpermissionsrequest(this, arrays.aslist("publish_actions"));         // set new publish permission request         session.requestnewpublishpermissions(newpermissionsrequest);          bundle params = new bundle();         //...        } } 

maybe answer might this: sso (singe sign-on) not working when facebook app installed on device: on call method , said:

since call() gets called anytime there change in session, session.isopen() true, if not check if permission set, enter in infinite loop.

you have this information requestnewpublishpermissions on docs:

this method used request permissions in addition app has been granted. happens after initial connection has been made facebook.

i saw solution on step: add publishing logic hence can read:

the method first check if logged-in user has granted app publish permissions; if have not, prompted reauthorize app , grant missing permissions.

i hope you.


Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -