php - Can't Log in with Facebook when I export my application -
i built app facebook sdk, working fine on emulator, when exported app run on mobile device, couldn't log in, frustrating because first app , thought working without errors.
my login in works registering button too. when without account tries login, automatically creates account using data facebook.
i'm using php insert data database, i'm calling function when tries log in:
case "loginfb": facebook_func($_post['email'],$_post['name'],$_post['gender'],$_post['image']);
my function calls query check if sent e-mail exists normal login, else, creates new account.
function facebook_func($email,$name,$gender,$image){ $result = db_queries("select * users email='$email'"); $row = mysqli_fetch_array($result); if($row[16] == 1){ //row 16 check if account uses social network login if($row[0]){ //check if id exists on database echo $row[0]; online_func($row[3],$row[0]); }else{ //inserts new account database //echo id user } }
i'm echoing id user save in java session.
session code:
public class newsession extends application { session session = new session(); public string getuserid() { return session.suserid; } }
my main activity full code:
public class mainactivity extends activity { private edittext email, password; private textview status; private callbackmanager callbackmanager; private loginbutton loginbutton; @override protected void onactivityresult(int requestcode, int responsecode, intent data) { super.onactivityresult(requestcode, responsecode, data); callbackmanager.onactivityresult(requestcode, responsecode, data); } @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); facebooksdk.sdkinitialize(this.getapplicationcontext()); setcontentview(r.layout.activity_main); email = (edittext) findviewbyid(r.id.email); password = (edittext) findviewbyid(r.id.password); status = (textview) findviewbyid(r.id.statusfield); callbackmanager = callbackmanager.factory.create(); loginbutton = (loginbutton) findviewbyid(r.id.login_button); list < string > permissionneeds = arrays.aslist("user_photos", "email"); loginbutton.setreadpermissions(permissionneeds); loginbutton.registercallback(callbackmanager, new facebookcallback < loginresult > () {@override public void onsuccess(loginresult loginresult) { system.out.println("onsuccess"); graphrequest request = graphrequest.newmerequest(loginresult.getaccesstoken(), new graphrequest.graphjsonobjectcallback() { @override public void oncompleted(jsonobject object, graphresponse response) { // todo auto-generated method stub // application code log.v("loginactivity", response.tostring()); //system.out.println("check: " + response.tostring()); try { string id = object.getstring("id"); string name = object.getstring("name"); string image = "http://graph.facebook.com/" + id + "/picture?width=600&height=600"; string email = object.getstring("email"); string gender = object.getstring("gender"); string getgender = ""; if (getgender.equals("male")) { getgender = "2"; } else { getgender = "1"; } facebooklogin(email, name, getgender, image); } catch (jsonexception e) { e.printstacktrace(); } } }); bundle parameters = new bundle(); parameters.putstring("fields", "id,name,email,gender"); request.setparameters(parameters); request.executeasync(); } @override public void oncancel() { system.out.println("oncancel"); } @override public void onerror(facebookexception exception) { system.out.println("onerror"); log.v("loginactivity", exception.getcause().tostring()); } }); } public void login(view view) { string getemail = email.gettext().tostring(); string getpassword = password.gettext().tostring(); new signinactivity(this, status).execute(getemail, getpassword); } public void facebooklogin(string email, string name, string gender, string image) { new fbsigninactivity(this, status).execute(email, name, gender, image); toast.maketext(getbasecontext(), "...", toast.length_long).show(); } }
my facebook login class
public class fbsigninactivity extends asynctask < string, void, string > { private textview statusfield; private context context; private static final int long_delay = 3500; // 3.5 seconds public fbsigninactivity(context context, textview statusfield) { this.context = context; this.statusfield = statusfield; } @override protected string doinbackground(string...arg0) { try { string getemail = (string) arg0[0]; string getname = (string) arg0[1]; string getgender = (string) arg0[2]; string getimage = (string) arg0[3]; string link = "http://www.website.pt/android/index.php?section=loginfb"; string data = urlencoder.encode("email", "utf-8") + "=" + urlencoder.encode(getemail, "utf-8"); data += "&" + urlencoder.encode("name", "utf-8") + "=" + urlencoder.encode(getname, "utf-8"); data += "&" + urlencoder.encode("gender", "utf-8") + "=" + urlencoder.encode(getgender, "utf-8"); data += "&" + urlencoder.encode("image", "utf-8") + "=" + urlencoder.encode(getimage, "utf-8"); url url = new url(link); urlconnection conn = url.openconnection(); conn.setdooutput(true); outputstreamwriter wr = new outputstreamwriter(conn.getoutputstream()); wr.write(data); wr.flush(); authenticator.setdefault(new authenticator() { protected passwordauthentication getpasswordauthentication() { return new passwordauthentication("user", "pass".tochararray()); } }); bufferedreader reader = new bufferedreader(new inputstreamreader(conn.getinputstream())); stringbuilder sb = new stringbuilder(); string line = null; // read server response while ((line = reader.readline()) != null) { sb.append(line); break; } return sb.tostring(); } catch (exception e) { return new string("exception: " + e.getmessage()); } } @override protected void onpostexecute(string result) { if (result == "") { toast.maketext(context, "shows error", toast.length_long).show(); } else { toast.maketext(context, "welcome message", toast.length_long).show(); string newuser = result.substring(0, 1); string newid = result.substring(1); if (newuser.equals("n")) { toast.maketext(context, "...", toast.length_long).show(); session.suserid = newid; intent in = new intent(context, editprofile.class); in .putextra("checku", "new"); context.startactivity( in ); }else{ context.startactivity(new intent(context, listusersactivity.class)); session.suserid = result; } } } }
thanks.
when create release apk, it's signed different keystore, first key hash created , put facebook app settings won't work release apk.
you need key hash, new apk, , add settings well.
Comments
Post a Comment