skip to Main Content

I achieved authentication between my android app and Facebook profile. I am able to get the logged in user data. However I require to get the users (only) playing the game (step 1).

This is my code so far:

 GraphRequest request =  new GraphRequest(
            AccessToken.getCurrentAccessToken(),
            "/{user-id}/friends",
            null,
            HttpMethod.GET,
            new GraphRequest.Callback() {
                public void onCompleted(GraphResponse response) {


                }
            }
    ).executeAsync();

Technically my response should be in JSON format, and I should be able to take from it what i need. However whenever i try that my project freezes and restarts.

For step2, do you have any suggestions on how to send the highest score from my application to post it on facebook, then be able to retrieve it and show it once i get the friend list playing the game?

Thank you

2

Answers


  1. Chosen as BEST ANSWER

    I was able to solve it using threads.

    final GraphRequest request_getFriends = new GraphRequest(
                        AccessToken.getCurrentAccessToken(),
                        "/" + AccessToken.getCurrentAccessToken().getUserId() + "/friends?",
                        null,
                        HttpMethod.GET,
                        new GraphRequest.Callback() {
    
                            @Override
                            public void onCompleted(GraphResponse response) {
    
                                JSONObject object = response.getJSONObject();
                                try {
                                    if (object !=null){
                                    JSONArray data = object.getJSONArray("data");
                                    for (int i = 0; i < data.length(); i++) {
                                        String id = data.getJSONObject(i).getString("id");
                                        String name = data.getJSONObject(i).getString("name");
                                        ListOfFriendsIDS.add(id);
                                        ListOfFriendsNames.add(name);
                                    }
                                    }
                                } catch (JSONException e) {
    
                                }
                            }
                        }
                );
    
    
                Thread t = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        request_getFriends.executeAndWait();
                    }
                }
                );
    
                t.start();
    

    The code before was executing asynchronously there my result wasn't being fetched properly.


  2. Use this GameRequestDialog to load the friends who are non app users.

    GameRequestDialog dialog;
    GameRequestContent content = new 
    GameRequestContent.Builder().
                setTitle("title").
                setMessage("message").
           setFilters(GameRequestContent.Filters.APP_NON_USERS) 
    .build();
    dialog.show(content);
    

    Along with this, go through this it will provide a great help. It is the sample project of facebook implementations.

    https://github.com/fbsamples/android-friend-smash

    Hope that helps

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search