Reputation: 113
i have very strange situetion. I 'm working facebook sdk in android. i wrote login code and also can check username and user id.but this code does not working when divice hase facebook application(i uninstalled it and then worked perfect) this is a my code
public void LoginFacebook() {
mFacebook.authorize(this, mPermissions, new LoginDialogListener());
}
private final class LoginDialogListener implements DialogListener {
public void onComplete(Bundle values) {
SessionStore.save(mFacebook, getApplicationContext());
getProfileInformation();
}
public void onCancel() {
SessionEvents.onLoginError("Action Canceled");
}
@Override
public void onFacebookError(FacebookError error) {
SessionEvents.onLoginError(error.getMessage());
}
@Override
public void onError(DialogError error) {
SessionEvents.onLoginError(error.getMessage());
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}
@SuppressLint("SdCardPath")
public void getProfileInformation() {
mAsyncRunner.request("me", new BaseRequestListener() {
@SuppressLint("CommitPrefEdits")
@Override
public void onComplete(String response, Object state) {
final String json = response;
runOnUiThread(new Runnable() {
@Override
public void run() {
try {
JSONObject profile = new JSONObject(json);
facebook_userid = profile.getString("id");
facebook_username = profile.getString("name");
facebook_username = facebook_username.replace(
"%20", " ");
editor.putString("fb_name", facebook_username);
editor.putString("fb_id", facebook_userid);
fb_name.setText(facebook_username);
getFacebookAvatar(facebook_userid);
editor.commit();
} catch (JSONException e) {
e.printStackTrace();
}
}
});
}
@Override
public void onIOException(IOException e, Object state) {
}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {
}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {
}
@Override
public void onFacebookError(FacebookError e, Object state) {
}
});
}
i have no idea what is a wrong. if anyone knows solution please help me thanks
Upvotes: 0
Views: 793
Reputation: 11245
You Can Do Like This.
public static void getuserdata() throws JSONException {
String Facebook = readT("https://graph.facebook.com/me?access_token="+mFacebook.getAccessToken()+"&fields=id,username)".replace(" ","%20"));
try
{
JSONObject jsonobj = new JSONObject(Facebook);
fb_id = jsonobj.getString("id");
fb_username = fb_fname+" "+fb_lname;
Log.e("..fb_username..........", fb_username);
}
catch (JSONException e)
{
e.printStackTrace();
}
}
Upvotes: 0
Reputation: 2178
Enable Client Deep Linking,Single Sign On and in advance tab OAuth Login from devlopers.facebook.com
Upvotes: 1