android - Facebook SDK: not "opened" session state while creating WebDialog.FeedDialogBuilder -
i faced such wierd bug while implementing facebook share info. made stages described on facebook tutorial facebook tutorial - share info
but while trying create example of webdialog.feeddialog
private void publishfeeddialog() { bundle params = new bundle(); params.putstring("name", getstring(r.string.name_fb)); params.putstring("description", getstring(r.string.description_fb)); params.putstring("link", getstring(r.string.share_link_fb)); params.putstring("picture", getstring(r.string.pictute_url_fb)); session session = session.getactivesession(); log.i(tag, "session = " + session + " isopen = " + session.isopened() + " isclosed = " + session.isclosed()); webdialog feeddialog = (new webdialog.feeddialogbuilder(this, session.getactivesession(), params)) .setoncompletelistener(new 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) { toast.maketext(mainactivity.this, "posted story, id: " + postid, toast.length_short).show(); } else { // user clicked cancel button toast.maketext(mainactivity.this, "publish cancelled", toast.length_short).show(); } } else if (error instanceof facebookoperationcanceledexception) { // user clicked "x" button toast.maketext(mainactivity.this, "publish cancelled", toast.length_short).show(); } else { // generic, ex: network error toast.maketext(mainactivity.this, "error posting story", toast.length_short).show(); } } }).build(); feeddialog.show(); }
i caught facebookexception!
09-22 19:34:49.325: e/activitythread(12202): failed find provider info com.facebook.katana.provider.platformprovider 09-22 19:34:49.325: i/mainactivity(12202): session = {session state:created, token:{accesstoken token:access_token_removed permissions:[]}, appid:1111111111111} isopen = false isclosed = false 09-22 19:34:49.325: d/androidruntime(12202): shutting down vm 09-22 19:34:49.325: w/dalvikvm(12202): threadid=1: thread exiting uncaught exception (group=0x418cc700) 09-22 19:34:49.325: e/activitythread(12202): failed find provider info com.facebook.wakizashi.provider.platformprovider 09-22 19:34:49.405: d/dalvikvm(12202): gc_for_alloc freed 891k, 9% free 10493k/11452k, paused 21ms, total 21ms 09-22 19:34:52.365: e/androidruntime(12202): fatal exception: main 09-22 19:34:52.365: e/androidruntime(12202): java.lang.illegalstateexception: not execute method of activity 09-22 19:34:52.365: e/androidruntime(12202): at android.view.view$1.onclick(view.java:3633) 09-22 19:34:52.365: e/androidruntime(12202): at android.view.view.performclick(view.java:4240) 09-22 19:34:52.365: e/androidruntime(12202): at android.view.view$performclick.run(view.java:17721) 09-22 19:34:52.365: e/androidruntime(12202): at android.os.handler.handlecallback(handler.java:730) 09-22 19:34:52.365: e/androidruntime(12202): at android.os.handler.dispatchmessage(handler.java:92) 09-22 19:34:52.365: e/androidruntime(12202): at android.os.looper.loop(looper.java:137) 09-22 19:34:52.365: e/androidruntime(12202): at android.app.activitythread.main(activitythread.java:5103) 09-22 19:34:52.365: e/androidruntime(12202): at java.lang.reflect.method.invokenative(native method) 09-22 19:34:52.365: e/androidruntime(12202): at java.lang.reflect.method.invoke(method.java:525) 09-22 19:34:52.365: e/androidruntime(12202): at com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:737) 09-22 19:34:52.365: e/androidruntime(12202): at com.android.internal.os.zygoteinit.main(zygoteinit.java:553) 09-22 19:34:52.365: e/androidruntime(12202): at dalvik.system.nativestart.main(native method) 09-22 19:34:52.365: e/androidruntime(12202): caused by: java.lang.reflect.invocationtargetexception 09-22 19:34:52.365: e/androidruntime(12202): at java.lang.reflect.method.invokenative(native method) 09-22 19:34:52.365: e/androidruntime(12202): at java.lang.reflect.method.invoke(method.java:525) 09-22 19:34:52.365: e/androidruntime(12202): at android.view.view$1.onclick(view.java:3628) 09-22 19:34:52.365: e/androidruntime(12202): ... 11 more 09-22 19:34:52.365: e/androidruntime(12202): caused by: com.facebook.facebookexception: attempted use session not open. 09-22 19:34:52.365: e/androidruntime(12202): at com.facebook.widget.webdialog$builderbase.<init>(webdialog.java:485) 09-22 19:34:52.365: e/androidruntime(12202): at com.facebook.widget.webdialog$feeddialogbuilder.<init>(webdialog.java:669) 09-22 19:34:52.365: e/androidruntime(12202): at com.kaeriasarl.psslite.activities.mainactivity.publishfeeddialog(mainactivity.java:131) 09-22 19:34:52.365: e/androidruntime(12202): at com.kaeriasarl.psslite.activities.mainactivity.sharelinktofacebook(mainactivity.java:116) 09-22 19:34:52.365: e/androidruntime(12202): at com.kaeriasarl.psslite.activities.mainactivity.onclickfeature(mainactivity.java:99) 09-22 19:34:52.365: e/androidruntime(12202): ... 14 more 09-22 19:34:52.475: i/gav3(12202): thread[gathread,5,main]: no campaign data found.
as can understand logs main trouble result of session.getactivesession() should not null , should opened see session has status created! made stages facebook tutorial said! help, please!
after investigation solved problem:
1) before creating feeddialog should check if active session opened , if not should directly open active session
if (session.getactivesession() == null || !session.getactivesession().isopened()) { session.openactivesession(mainactivity.this, true, callback); } else { publishfeeddialog(); }
2) , call publishfeeddialog() in session.statuscallback
private session.statuscallback callback = new session.statuscallback() { @override public void call(session session, sessionstate state, exception exception) { if (state.isopened() && isfbshare) { publishfeeddialog(); } } };
Comments
Post a Comment