Fetching user group from facebook using facebook api

浪子不回头ぞ 提交于 2019-12-08 13:07:35

问题


I want to fetch the user groups and want to list them but I am unable to fetch the groups from Facebook, though I am able to do

*Successful Login
*fetch friend list 
*i have also allowed the permission user_groups for fetching user groups

here I am doing like this for fetching user group

AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
mAsyncRunner.request("me/groups", params,
                    new GroupsRequestListener());

public class GroupsRequestListener extends BaseRequestListener {

    @Override
    public void onComplete(final String response, final Object state) {
        dialog.cancel();
        Log.v("response", response);
        Intent myIntent = new Intent(getApplicationContext(),
                GroupsList.class);
        myIntent.putExtra("API_RESPONSE", response);
        startActivity(myIntent);
    }

    public void onFacebookError(FacebookError error) {
        dialog.cancel();

        Toast.makeText(getApplicationContext(),
                "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
                .show();
    }

}

But I got a response, something like this on log

06-15 07:43:19.563: V/response(645): {"error":{"message":"(#100) Unknown fields:    location,birthday","type":"OAuthException","code":100}}

"me/friends" parameters is ok for fetching friend list. Is the parameter "me/groups" right for fetching user group?


回答1:


Thanks @Christoph Eberhardt. i got the solution with your help. what i was doing mistake is the worng request parameters. the params should be

Bundle params = new Bundle();
params.putString("fields", "name");

after setting request params,above code works perfectly. The complete solution for fetching user group is

//onCreate
AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);
Bundle params = new Bundle();
params.putString("fields", "name");

mAsyncRunner.request("me/groups", params,
                new GroupsRequestListener());

//then

public class GroupsRequestListener extends BaseRequestListener {

@Override
public void onComplete(final String response, final Object state) {
    dialog.cancel();
    Log.v("response", response);
    Intent myIntent = new Intent(getApplicationContext(),
            GroupsList.class);
    myIntent.putExtra("API_RESPONSE", response);
    startActivity(myIntent);
    }

public void onFacebookError(FacebookError error) {
    dialog.cancel();

    Toast.makeText(getApplicationContext(),
            "Facebook Error: " + error.getMessage(), Toast.LENGTH_SHORT)
            .show();
    }

}



回答2:


The error points to a request parameter mistake on your side. When requesting your friends, you can explicitly request the birthday and the location of your friend. Probably groups don't have those attributes.

Check your request parameters and you should be fine.



来源:https://stackoverflow.com/questions/11047025/fetching-user-group-from-facebook-using-facebook-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!