facebook android integration not working for share with friends -


i have made simple program in android facebook android integaration,i have tried below:it shows facebook login dialog box , logged in after shows myapp , ask share facebook friends when press"yes"..it says failed post on wall"....please tell me whats problem,, code below:

main.java

package com.example.facbk;  import com.facebook.android.asyncfacebookrunner; import com.facebook.android.dialogerror; import com.facebook.android.facebook; import com.facebook.android.facebook.dialoglistener; import com.facebook.android.facebookerror; import com.parse.logincallback; import com.parse.parse; import com.parse.parsefacebookutils; import com.parse.parseuser; import android.net.parseexception; import android.os.bundle; import android.provider.syncstatecontract.constants; import android.app.activity; import android.content.context; import android.content.intent; import android.content.sharedpreferences; import android.content.sharedpreferences.editor; import android.util.log; import android.view.menu; import android.view.view; import android.view.view.onclicklistener; import android.view.window; import android.widget.button; import android.widget.toast;  public class mainactivity extends activity {     private static final string app_id = "454641867918042";     private static final string[] permissions = new string[] {"publish_stream"};      private static final string token = "access_token";         private static final string expires = "expires_in";         private static final string key = "facebook-credentials";      private facebook facebook;     private string messagetopost;      public boolean savecredentials(facebook facebook) {             editor editor = getapplicationcontext().getsharedpreferences(key, context.mode_private).edit();             editor.putstring(token, facebook.getaccesstoken());             editor.putlong(expires, facebook.getaccessexpires());             system.out.println("hello token");             system.out.println(facebook.getaccesstoken());             return editor.commit();          }          public boolean restorecredentials(facebook facebook) {             sharedpreferences sharedpreferences = getapplicationcontext().getsharedpreferences(key, context.mode_private);             facebook.setaccesstoken(sharedpreferences.getstring(token, null));             facebook.setaccessexpires(sharedpreferences.getlong(expires, 0));             return facebook.issessionvalid();         }     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         facebook = new facebook(app_id);         restorecredentials(facebook);          requestwindowfeature(window.feature_no_title);          setcontentview(r.layout.activity_main);          string facebookmessage = getintent().getstringextra("facebookmessage");         if (facebookmessage == null){             facebookmessage = "test wall post";         }         messagetopost = facebookmessage;     }      public void donotshare(view button){         finish();     }     public void share(view button){         if (! facebook.issessionvalid()) {             loginandposttowall();         }         else {             posttowall(messagetopost);         }     }      public void loginandposttowall(){          facebook.authorize(this, permissions, facebook.force_dialog_auth, new logindialoglistener());     }      public void posttowall(string message){         bundle parameters = new bundle();                 parameters.putstring("message", message);                 parameters.putstring("description", "topic share");                 try {                     facebook.request("me");             string response = facebook.request("me/feed", parameters, "post");             log.d("tests", "got response: " + response);             if (response == null || response.equals("") ||                     response.equals("false")) {                 showtoast("blank response.");             }             else {                 showtoast("message posted facebook wall!");             }             finish();         } catch (exception e) {             showtoast("failed post wall!");             e.printstacktrace();             finish();         }     }      class logindialoglistener implements dialoglistener {         public void oncomplete(bundle values) {             savecredentials(facebook);             if (messagetopost != null){             posttowall(messagetopost);         }         }         public void onfacebookerror(facebookerror error) {             showtoast("authentication facebook failed!");             finish();         }         public void onerror(dialogerror error) {             showtoast("authentication facebook failed!");             finish();         }         public void oncancel() {             showtoast("authentication facebook cancelled!");             finish();         }     }      private void showtoast(string message){         toast.maketext(getapplicationcontext(), message, toast.length_short).show();     } } 

logcat

07-11 18:45:55.200: e/libegl(1006): call opengl es api no current context (logged once per thread) 07-11 18:45:55.200: d/shaderprogram(1006): couldn't load vertex shader! 07-11 18:45:55.211: e/libegl(1006): call opengl es api no current context (logged once per thread) 07-11 18:45:55.211: d/shaderprogram(1006): couldn't load vertex shader! 07-11 18:45:55.211: e/libegl(1006): call opengl es api no current context (logged once per thread) 07-11 18:45:55.211: d/shaderprogram(1006): couldn't load vertex shader! 07-11 18:45:55.211: e/libegl(1006): call opengl es api no current context (logged once per thread) 07-11 18:45:55.221: d/shaderprogram(1006): couldn't load vertex shader! 07-11 18:45:55.221: e/libegl(1006): call opengl es api no current context (logged once per thread) 07-11 18:45:55.221: d/shaderprogram(1006): couldn't load vertex shader! 07-11 18:46:12.610: d/facebooksdk.webdialog(1006): webview loading url: https://m.facebook.com/dialog/oauth/confirm 07-11 18:46:14.720: d/facebooksdk.webdialog(1006): redirect url: fbconnect://success#access_token=caagdfo8jitobaeas1rwo2odzcg4jvseoqv4hxmzblhkrvgzcjdlx07bfvmy7fomra1vbnxtc0otpnvmagczcbxs3wqsa4bakoewdd7atg8vkzboyr6clafzcyzavdgupz1kbmtlal99vauzazxswbsbe&expires_in=5157278 07-11 18:46:15.370: d/dalvikvm(1006): gc_concurrent freed 427k, 6% free 9524k/10055k, paused 7ms+26ms 07-11 18:46:15.831: i/system.out(1006): hello token 07-11 18:46:15.831: i/system.out(1006): caagdfo8jitobaeas1rwo2odzcg4jvseoqv4hxmzblhkrvgzcjdlx07bfvmy7fomra1vbnxtc0otpnvmagczcbxs3wqsa4bakoewdd7atg8vkzboyr6clafzcyzavdgupz1kbmtlal99vauzazxswbsbe 07-11 18:46:15.910: d/facebook-util(1006): url: https://graph.facebook.com/me?access_token=caagdfo8jitobaeas1rwo2odzcg4jvseoqv4hxmzblhkrvgzcjdlx07bfvmy7fomra1vbnxtc0otpnvmagczcbxs3wqsa4bakoewdd7atg8vkzboyr6clafzcyzavdgupz1kbmtlal99vauzazxswbsbe&format=json 07-11 18:46:16.030: w/system.err(1006): android.os.networkonmainthreadexception 07-11 18:46:16.061: w/system.err(1006):     @ android.os.strictmode$androidblockguardpolicy.onnetwork(strictmode.java:1099) 07-11 18:46:16.061: w/system.err(1006):     @ java.net.inetaddress.lookuphostbyname(inetaddress.java:391) 07-11 18:46:16.061: w/system.err(1006):     @ java.net.inetaddress.getallbynameimpl(inetaddress.java:242) 07-11 18:46:16.070: w/system.err(1006):     @ java.net.inetaddress.getallbyname(inetaddress.java:220) 07-11 18:46:16.070: w/system.err(1006):     @ libcore.net.http.httpconnection.<init>(httpconnection.java:71) 07-11 18:46:16.070: w/system.err(1006):     @ libcore.net.http.httpconnection.<init>(httpconnection.java:50) 07-11 18:46:16.081: w/system.err(1006):     @ libcore.net.http.httpconnection$address.connect(httpconnection.java:351) 07-11 18:46:16.081: w/system.err(1006):     @ libcore.net.http.httpconnectionpool.get(httpconnectionpool.java:86) 07-11 18:46:16.081: w/system.err(1006):     @ libcore.net.http.httpconnection.connect(httpconnection.java:128) 07-11 18:46:16.081: w/system.err(1006):     @ libcore.net.http.httpengine.opensocketconnection(httpengine.java:308) 07-11 18:46:16.091: w/system.err(1006):     @ libcore.net.http.httpsurlconnectionimpl$httpsengine.makesslconnection(httpsurlconnectionimpl.java:460) 07-11 18:46:16.091: w/system.err(1006):     @ libcore.net.http.httpsurlconnectionimpl$httpsengine.connect(httpsurlconnectionimpl.java:432) 07-11 18:46:16.091: w/system.err(1006):     @ libcore.net.http.httpengine.sendsocketrequest(httpengine.java:282) 07-11 18:46:16.091: w/system.err(1006):     @ libcore.net.http.httpengine.sendrequest(httpengine.java:232) 07-11 18:46:16.100: w/system.err(1006):     @ libcore.net.http.httpurlconnectionimpl.getresponse(httpurlconnectionimpl.java:273) 07-11 18:46:16.110: w/system.err(1006):     @ libcore.net.http.httpurlconnectionimpl.getinputstream(httpurlconnectionimpl.java:168) 07-11 18:46:16.110: w/system.err(1006):     @ libcore.net.http.httpsurlconnectionimpl.getinputstream(httpsurlconnectionimpl.java:270) 07-11 18:46:16.120: w/system.err(1006):     @ com.facebook.android.util.openurl(util.java:219) 07-11 18:46:16.120: w/system.err(1006):     @ com.facebook.android.facebook.requestimpl(facebook.java:806) 07-11 18:46:16.130: w/system.err(1006):     @ com.facebook.android.facebook.request(facebook.java:732) 07-11 18:46:16.130: w/system.err(1006):     @ com.example.facbk.mainactivity.posttowall(mainactivity.java:93) 07-11 18:46:16.130: w/system.err(1006):     @ com.example.facbk.mainactivity$logindialoglistener.oncomplete(mainactivity.java:115) 07-11 18:46:16.140: w/system.err(1006):     @ com.facebook.android.facebook.onsessioncallback(facebook.java:345) 07-11 18:46:16.140: w/system.err(1006):     @ com.facebook.android.facebook.access$11(facebook.java:326) 07-11 18:46:16.140: w/system.err(1006):     @ com.facebook.android.facebook$1.call(facebook.java:304) 07-11 18:46:16.151: w/system.err(1006):     @ com.facebook.session$3$1.run(session.java:1190) 07-11 18:46:16.151: w/system.err(1006):     @ android.os.handler.handlecallback(handler.java:605) 07-11 18:46:16.151: w/system.err(1006):     @ android.os.handler.dispatchmessage(handler.java:92) 07-11 18:46:16.160: w/system.err(1006):     @ android.os.looper.loop(looper.java:137) 07-11 18:46:16.160: w/system.err(1006):     @ android.app.activitythread.main(activitythread.java:4424) 07-11 18:46:16.171: w/system.err(1006):     @ java.lang.reflect.method.invokenative(native method) 07-11 18:46:16.181: w/system.err(1006):     @ java.lang.reflect.method.invoke(method.java:511) 07-11 18:46:16.181: w/system.err(1006):     @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:784) 07-11 18:46:16.191: w/system.err(1006):     @ com.android.internal.os.zygoteinit.main(zygoteinit.java:551) 07-11 18:46:16.191: w/system.err(1006):     @ dalvik.system.nativestart.main(native method) 07-11 18:46:19.750: i/jdwp(1006): ignoring second debugger -- accepting , dropping 

there 2 issues code.

the first you're using deprecated version of facebook sdk. if you're using 3.0.x of sdk, please not use facebook class, , use session , request classes instead. see https://developers.facebook.com/android/ tutorials , samples. doesn't affect correctness, brings me ...

your issue you're doing network request on main thread (exactly exception says). need wrap facebook.request call inside asynctask's doinbackground method.


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -