0

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

viviano
  • 113
  • 1
  • 7

2 Answers2

1

Enable Client Deep Linking,Single Sign On and in advance tab OAuth Login from devlopers.facebook.com

MrDumb
  • 2,140
  • 1
  • 21
  • 31
  • i did not understand it.can you share more information ? – viviano Oct 16 '14 at 12:30
  • You must have registered your app on developers.facebook.com... IF not then you have to register your android app there. it will also ask your SHA KEY....It has written there how to get SHA – MrDumb Oct 16 '14 at 12:31
  • yes i registered my app on developer.facebok.com my app working only when in divice does not has install facebook application – viviano Oct 16 '14 at 12:34
  • On the same page there is option of Deep Linking and Single Sign On turn that on and on same page under advanced there is an option of OAuth Login. Make sure these are turned On – MrDumb Oct 16 '14 at 12:36
  • Yes And in advanced tab there is option of OAuth Login did you turn that on also ?? is it working or not ? Also make sure you Sha is right fallow this [this](https://developers.facebook.com/docs/android/getting-started#create-app) – MrDumb Oct 16 '14 at 12:50
  • also not working. yes sha1 is right i also posted some post about sha1 http://stackoverflow.com/questions/26402449/android-connect-facebook-invalid-keyhash/26402644#26402644 – viviano Oct 16 '14 at 12:54
  • Did you sign you apk? After Signing it gets Changed. add debuggable="true" in menifest and then after signing log your apk see if it is correct. Right SHA will also show on the app once you sign your package. – MrDumb Oct 16 '14 at 12:59
  • i run my app with usb – viviano Oct 16 '14 at 13:20
0

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();
    }

}

Jay Rathod
  • 11,131
  • 6
  • 34
  • 58