android - Facebook Login and Post To Wall works for first time only -
i have strange situation.i trying integrate facebook app.but login , post wall works first time.i struck past 2 days , not find solution.
here code snippet:
//.............facebook.......................... private static final string app_id = "my app id"; // instance of facebook class private facebook facebook = new facebook(app_id); private asyncfacebookrunner masyncrunner; private sharedpreferences mprefs; string access_token; long expires; //............facebook..............................// else if(actionid == id_facebook) { masyncrunner = new asyncfacebookrunner(facebook); filename=mylist.get(posglobal).get("foldername"); mprefs = getpreferences(mode_private); access_token = mprefs.getstring("access_token", null); expires = mprefs.getlong("access_expires", 0); if (access_token != null) { facebook.setaccesstoken(access_token); log.d("fb sessions", "" + facebook.issessionvalid()); } if (expires != 0) { facebook.setaccessexpires(expires); } if (!facebook.issessionvalid()) { facebook.authorize(boondriveactivity.this, new string[] { "email", "publish_stream" }, new dialoglistener() { @override public void oncancel() { // function handle cancel event } @override public void oncomplete(bundle values) { // function handle complete event // edit preferences , update facebook acess_token final sharedpreferences.editor editor = mprefs.edit(); editor.putstring("access_token", facebook.getaccesstoken()); editor.putlong("access_expires", facebook.getaccessexpires()); editor.commit(); layoutinflater inflater=boondriveactivity.this.getlayoutinflater(); view layout=inflater.inflate(r.layout.createsharedialoglinkedin,null); final alertdialog d1 = new alertdialog.builder(boondriveactivity.this) // other options here ... .setview(layout) .create(); d1.getwindow().setsoftinputmode(windowmanager.layoutparams.soft_input_adjust_resize); d1.show(); lntxtfilename=(textview)layout.findviewbyid(r.id.txtfilename); lnetmessage=(edittext)layout.findviewbyid(r.id.et_message); ln_btn_share=(button)layout.findviewbyid(r.id.btn_share); ln_btn_showlink=(button)layout.findviewbyid(r.id.btn_showlink); lnshowlink=(edittext)layout.findviewbyid(r.id.et_showlink); lntxtfilename.settext("share"+" "+filename+" "+"with:"); ln_btn_share.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub posttowall(); } }); } @override public void onerror(dialogerror error) { // function handle error } @override public void onfacebookerror(facebookerror fberror) { // function handle facebook errors } }); } }
i inflating customize view post on wall.for first time value of access_token null , expires zero.but when try share second time nothing happens.i debugged application , find there value in access_token expires , condition if (!facebook.issessionvalid()) not firing.any help??i know using deprecated method couldn't find updated tutorials or documentations.
here code of post wall:
/** * function post facebook wall * */ @suppresswarnings("deprecation") public void posttowall() { // post on user's wall. facebook.dialog(this, "feed", new dialoglistener() { @override public void onfacebookerror(facebookerror e) { } @override public void onerror(dialogerror e) { } @override public void oncomplete(bundle values) { } @override public void oncancel() { } }); }
update:
i using code generate hash:
// add code print out key hash try { packageinfo info = getpackagemanager().getpackageinfo( "com.india.webguru.bizboon", packagemanager.get_signatures); (signature signature : info.signatures) { messagedigest md = messagedigest.getinstance("sha"); md.update(signature.tobytearray()); log.d("keyhash:", base64.encodetostring(md.digest(), base64.default)); system.out.println("facebook hash===>"+base64.encodetostring(md.digest(), base64.default)); } } catch (namenotfoundexception e) { e.printstacktrace(); } catch (nosuchalgorithmexception e) { e.printstacktrace(); }
same issue solved following steps:
method 1
goto cmd : c:\program files (x86)\java\jdk1.7.0_02\bin
(use path)
1) generate debug key
keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64 3***w/****************= (require debug key)
2) generate hash key
keytool -exportcert -alias 3***w/****************= -keystore "c:\users\smartphone developer\.android\debug.keystore" | openssl sha1 -binary | openssl base64 *******+************= (require hash key)
note: if hash key gives error, copy paste same hash generated facebook in exception & add "=" in end
..
valid hash facebook
= ***************/a*0=
edit: download openssl & place folder c:\openssl
update 1 (step vise): after placing openssl folder in c drive, open cmd & write commands:
method 2
step 1
c:\program files\java\jre7>bin
step 2
c:\program files\java\jre7\bin>keytool -exportcert -alias androiddebugkey -keyst ore "c:\users\smartphone developer\.android\debug.keystore" | "c:\openssl\bin\openssl" sha 1 -binary | "c:\openssl\bin\openssl" base64
enter keystore password: android
u***zt***t***2t***bu*fj***w=
step 3
c:\program files\java\jre7\bin>keytool -exportcert -alias u***zt***t***2t***bu*fj***w= -keystore "c:\users\smartphone developer\.android\debug.keystore" | "c:\openssl\bin \openssl" sha1 -binary | "c:\openssl\bin\openssl" base64
enter keystore password: android
d*w+i***9/6vs***np***cf***g= (required hash)
if downloaded correct openssl must work, tested procedure..
Comments
Post a Comment