问题
I am developing facebok sample demo for get all friend list of login user. I am running Friend Picker Sample successfully,But getstuck to extract all the details of friends like email,first_name,last_name etc.I am getting only id,name.
If anyone have idea please reply.
Here is mycode:-
public void getFriends(Properties properties, final OnFriendsRequestListener onFriendsRequestListener)
{
// if we are logged in
if (isLogin())
{
// move these params to method call parameters
Session session = getOpenSession();
Bundle bundle = null;
if (properties != null)
{
bundle = properties.getBundle();
}
Request request = new Request(session, "me/friends", bundle, HttpMethod.GET, new Request.Callback()
{
@Override
public void onCompleted(Response response)
{
List<GraphUser> graphUsers = typedListFromResponse(response, GraphUser.class);
FacebookRequestError error = response.getError();
if (error != null)
{
// log
logError("failed to get friends", error.getException());
// callback with 'exception'
if (onFriendsRequestListener != null)
{
onFriendsRequestListener.onException(error.getException());
}
}
else
{
// callback with 'complete'
if (onFriendsRequestListener != null)
{
List<Profile> friends = new ArrayList<Profile>(graphUsers.size());
for (GraphUser graphUser: graphUsers)
{
friends.add(Profile.create(graphUser));
}
onFriendsRequestListener.onComplete(friends);
}
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
// callback with 'thinking'
if (onFriendsRequestListener != null)
{
onFriendsRequestListener.onThinking();
}
}
else
{
String reason = Errors.getError(ErrorMsg.LOGIN);
logError(reason, null);
// callback with 'fail' due to not being loged
if (onFriendsRequestListener != null)
{
onFriendsRequestListener.onFail(reason);
}
}
}
Thanks in advance...
回答1:
After very sturggle i try some methods and finally found solution.
public void getFriendsList() {
Bundle bundle=new Bundle();
bundle.putString("fields","id,name,first_name,last_name,email,picture,gender,birthday,work");
mAsyncRunner.request("me/friends",bundle,friendsRequsetListener,null);
}
RequestListener friendsRequsetListener =new RequestListener() {
@Override
public void onMalformedURLException(MalformedURLException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onIOException(IOException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFileNotFoundException(FileNotFoundException e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onFacebookError(FacebookError e, Object state) {
// TODO Auto-generated method stub
}
@Override
public void onComplete(String response, Object state) {
// TODO Auto-generated method stub
String json = response;
try {
Log.e("Response","========>"+json);
}
catch(Exception e){
}
}
};
I hope this will help others. Thanks!!
来源:https://stackoverflow.com/questions/20703238/unable-get-all-fields-of-friend-list-in-facebook-sdk-sample-and-in-friend-picker