从Facebook帐户API获取位置

时间:2017-12-06 01:06:50

标签: android facebook-graph-api

我已经做了很多尝试让这个帐户的城市在应用程序上查看该帐户但它不起作用

//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) {

            }
        });
    }

在这里,我试着呈现体验区域

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

我可以在Chrome上查看Json facebook吗? ,我不知道如何在Facebook上安排Json

我搜索了很多,但我没有得到这个城市。这是我的刀片中的问题还是请帮助我真的谢谢你

0 个答案:

没有答案