android - Facebook session state OPENING -


i can login app share something. needs opened session state. however, when not logged in, want share something, need open session. using viewpager e.g. when go 1 page , code

session.openactivesession(getactivity(), true, new statuscallback() {        @override        public void call(session session, sessionstate state, exception exception) {        } }); 

is in beginning of code, session becomes active, , automatically logged in, wrong! that's why put code block onclicklistener, want open session if click share button in app:

if (session != null && session.isopened()) {   publishfeeddialog(); } else {    session.openactivesession(getactivity(), true, new statuscallback() {         @override         public void call(session session, sessionstate state, exception exception) {         }     });    publishfeeddialog(); }  private void publishfeeddialog() {   session = session.getactivesession();   log.i("tag", session.getstate() + ""); //opening     webdialog feeddialog = (                     new webdialog.feeddialogbuilder(getactivity(),                         session.getactivesession(),                         params))                     .setoncompletelistener(new oncompletelistener() {                          @override                         public void oncomplete(bundle values,                             facebookexception error) {                              if (error == null) {                                     final string postid = values.getstring("post_id");                                     if (postid != null) {                                     } else {                                         // user clicked cancel button                                     }                                 } else if (error instanceof facebookoperationcanceledexception) {                                 } else {                                     // generic, ex: network error                                 }                         }                      })                     .build();                 feeddialog.show(); } 

the error:

attempted use session not open.

so open session in vain, because still opening when webdialog should appear.

please help.

try calling publishfeeddialog() inside call() after check status of session (do not use session.isopened(), use state.isopened() instead). checking state ensures session in open state , can used execute requests. statuscallback can called multiple times until session open, why should check status before sending request.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -