Home Get location from Facebook Account API
Reply: 0

Get location from Facebook Account API

zain
1#
zain Published in 2017-12-06 01:06:50Z

I've made lots of attempts to get the city for this account to view the account on the app but it dont work

//Login Facebook
    public void Login()
    {
        Dialog dialog = new Dialog(Home.this);
        dialog.setContentView(R.layout.customdialog_login);
        login_button = (LoginButton)dialog.findViewById(R.id.login_button);
        login_button.setReadPermissions("public_profile", "email", "user_birthday", "user_friends","user_location");
        callbackManager = CallbackManager.Factory.create();
        dialog.show();
        login_button.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
            @Override
            public void onSuccess(final LoginResult loginResult) {
                GraphRequest graphRequest = GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
                    @Override
                    public void onCompleted(final JSONObject object, GraphResponse response) {
                        try {
                            SaveSystem.SaveStringData("userid" , object.getString("id"));
                            SaveSystem.SaveStringData("first_name" , object.getString("first_name"));
                            SaveSystem.SaveStringData("last_name" , object.getString("last_name"));
                            SaveSystem.SaveStringData("gender" , object.getString("gender"));
                            SaveSystem.SaveStringData("admin" , "0");
                            SaveSystem.SaveStringData("ban" , "0");
                            SaveSystem.SaveStringData("type" , "facebook");

                            //CheckUser
                            final RequestQueue requestQueue = Volley.newRequestQueue(Home.this);
                            StringRequest stringRequest = new StringRequest(Request.Method.GET, Information.URL_CheckUsers + SaveSystem.LoadStringData("userid"), new Response.Listener<String>() {
                                @Override
                                public void onResponse(String response) {
                                    try {
                                        Toast.makeText(Home.this, "Location " + object.getJSONObject("location").getJSONObject("location").getString("city"), Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

                                    if(response.equals("0"))
                                    {
                                        //Add Account
                                        String URL_AddUser = Information.URL_AddUsers + SaveSystem.LoadStringData("userid") + "&username=" + SaveSystem.LoadStringData("first_name") + " " + SaveSystem.LoadStringData("last_name") + "&gender=" + SaveSystem.LoadStringData("gender") + "&admin=" + SaveSystem.LoadStringData("admin") + "&ban=" + SaveSystem.LoadStringData("ban") + "&type=" + SaveSystem.LoadStringData("type");
                                        StringRequest stringRequest1 = new StringRequest(Request.Method.GET, URL_AddUser , new Response.Listener<String>() {
                                            @Override
                                            public void onResponse(String response) {
                                                setAccountData();

                                            }
                                        }, new Response.ErrorListener() {
                                            @Override
                                            public void onErrorResponse(VolleyError error) {
                                                Toast.makeText(Home.this, "Failed", Toast.LENGTH_SHORT).show();
                                            }
                                        });
                                        requestQueue.add(stringRequest1);
                                    }
                                    else
                                    {
                                        setAccountData();
                                    }
                                }
                            }, new Response.ErrorListener() {
                                @Override
                                public void onErrorResponse(VolleyError error) {

                                }
                            });
                            requestQueue.add(stringRequest);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }
                    }
                });

                Bundle parameters = new Bundle();
                parameters.putString("fields", "id, first_name, last_name, email,gender, birthday, location{location}");
                graphRequest.setParameters(parameters);
                graphRequest.executeAsync();
            }
            @Override
            public void onCancel() {

            }
            @Override
            public void onError(FacebookException error) {

            }
        });
    }

here I try to present the area to experience

try {
                                        Toast.makeText(Home.this, "Location " + object.getJSONObject("location").getJSONObject("location").getString("city"), Toast.LENGTH_SHORT).show();
                                    } catch (JSONException e) {
                                        e.printStackTrace();
                                    }

can I view Json facebook on Chrome ?? , I do not know how to arrange Json on facebook

I searched a lot but I dont get the city. Is it a problem in my blades or what please help me really thank you

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301293 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO