I am new in Facebook integration with android. I've logged in to Facebook by using facebook-android-SDK. Now I want to get all friends details and display in ListView. How can I do this?
Please help me
Thanks in advance
Go with following code to get frends list :
Bundle params = new Bundle();
params.putString("fields", "name, picture");
JSONObject jsonFrends = Util.parseJson(facebook.request("me/friends", params));
I would recommend following the tutorial on Fetching User Data and then instead of executing
...
if (state.isOpened()) {
userInfoTextView.setVisibility(View.VISIBLE);
// Request user data and show the results
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// Display the parsed user info
userInfoTextView.setText(buildUserInfoDisplay(user));
}
}
});
}
...
use Request.executeMyFriendsRequestAsync which is part of the Request class.
EDIT: Which also has the advantage of using the Facebook Android SDK to parse the response.
You can do by this way :
Using the graph API: https://graph.facebook.com/me/friends?access_token="your access_token"
Related
Can I fetch all the posts data from a page with logged in user's access token ? or Is there any other way to retrieve all the posts data of a public page using Facebook Graph Api for Android ?
You will get facebook post data in json format that you can parse according to your requirement.
GraphRequest request = GraphRequest.newGraphPathRequest(
AccessToken.getAccessToken(),
"/YOUR_PAGE_ID/posts",
new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
// Insert your code here
Log.d("raw response ",response.getRawResponse());
}
});
request.executeAsync();
in android application :
i want to get a list of all friends of the person who login to my app , not only those who use the app ?
i use the following :
private void makeMeRequest(final Session session) {
// Make an API call to get user data and define a
// new callback to handle the response.
RequestAsyncTask request =new Request( session,
"/me/friends",
null,
HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
// TODO Auto-generated method stub
Log.e(LOG_TAG,"Members: " + response.toString());
}
}).executeAsync();
}
but the response returns empty list , although there are some apps that show person's friend list ,what can i do ??
It is not possible to get ALL friends with v2.0+, only with Apps created before end of April 2014 by using v1.0 of the Graph API. And it will only work until end of April 2015. See changelog for more information about the versions: https://developers.facebook.com/docs/apps/changelog
There is also invitable_friends and taggable_friends though, but they are reserved for Apps on facebook.com:
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/invitable_friends
https://developers.facebook.com/docs/graph-api/reference/v2.1/user/taggable_friends
This may also be interesting for inviting friends: https://developers.facebook.com/docs/games/requests/v2.1
When I try to save QBCustomObject, response from server sometimes it says
Base forbidden. Need User.
Before saving, I checked QBChatService.getInstance().isLoggedIn() and it returns true.
This error happens for both:
just after logging in
and, for example, 10 minutes afterwards
Disappears after re-launching the app and signing in process.
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put("name", name);
fields.put("User ID", currentUser.getId());
QBCustomObject qbCustomObject = new QBCustomObject();
qbCustomObject.setUserId(currentUser.getId());
qbCustomObject.setClassName("Group");
qbCustomObject.setFields(fields);
QBCustomObjects.createObject(qbCustomObject, new QBCallbackImpl() {...});
Here are the chain of actions which leads to creating QBCustomObject:
QBAuth.createSession() -> QBUsers.signIn() -> QBChatService.getInstance().loginWithUser()
Why does this error happen?
Seems like I've found the bug. I didn't used the QBUser object I got from .signIn() response. Here is what I mean:
QBUsers.signIn(user, new QBCallbackImpl() {
#Override
public void onComplete(Result result) {
if (result.isSuccess()) {
QBUser signedInUser = (((QBUserResult) result).getUser());
signedInUser.setPassword(password);
//...
loginToChat(signedInUser);
//...
}
});
Chat login and login to Application - they are different logins.
In order to create any object in QuickBlox (except a chat message) - you must act on the user's behalf
More info here how to create a record http://quickblox.com/developers/SimpleSample-customObjects-android#Create_record_using_Android_SDK
There you will find a link how to login a user to application http://quickblox.com/developers/SimpleSample-users-android#Sign_In_.26_Social_authorization
create your session with QBUser.
ex :- QBAuth.createSession(new QBUser("user_name", ""))
I am using Facebook SDK 3.5 and i am a bit confused. If i use FriendPickerFragment (from their example) it populates the fragment with the list of friends, but I only want to have the JSON or list of GraphUser only.
Does anybody know how to get that information using the picker fragment. I don't understand how they get the data to populate the fragment.
This is how i can see what is selected from the populated list:
List<GraphUser> selectedUsers = friendPickerFragment.getSelection();
for (GraphUser selectedUser : selectedUsers) { System.out.println("selectedUser: " + selectedUser);
}
But how can i get the entire list(selected or not)?
Request request = Request.newMyFriendsRequest(
Session.getActiveSession(),
new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
System.out.println("Users: " + users);
}
});
request.executeAsync();
Just make a graph request to me/friends. The SDK already provides you with a convenience method in Request.newMyFriendsRequest
I want tot send a friend request using the Facebook Android SDK. I'm currently using this code (which I got from here):
Bundle parameters = new Bundle();
parameters.putString("APP_ID","USERNAME");
facebook.dialog(this, "friends", parameters, this);
where APP_ID is the Facebook ID of my app and USERNAME is the username of the friend I want to add. This leads to the following error:
API Error Code:100
Invalid parameter
The parameter id is required
I thought the id parameter meant the APP_ID.
I have gone through the relevant documentation regarding dialogs at http://developers.facebook.com/docs/reference/dialogs/friends/ and http://developers.facebook.com/docs/reference/androidsdk/dialog/, but still can't figure it out.
Any help is appreciated.
Should be something like:
Bundle parameters = new Bundle();
parameters.putString("id", USER_ID);
facebook.dialog(this, "friends", parameters, this);
In case that this is an activity which also implements DialogListener.
As it says in the documentation:
app_id - Your application's identifier. Required, but automatically
specified by most SDKs.
id - Required. The ID or username of the
target user to add as a friend.
You can use:
WebDialog.RequestsDialogBuilder requestBuilder = (new WebDialog.RequestsDialogBuilder(this,
Session.getActiveSession(), params)).setOnCompleteListener(
new OnCompleteListener() {
#Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
} else {
final String requestId = values
.getString("request");
if (requestId != null) {
//if the user completed the action,
} else {
}
}
}
});
WebDialog requests = requestBuilder.build();
requests.show();
If you want to set the request to preselected friends just add the following to the requestBuilder:
requestBuilder.setTo("FRIEND_ID, ANOTHER_FRIEND_ID"), before building the dialog.
What is strange is that it accepts the list of friends as a concatenated list of ids, not an Array nor list. I didn't find in in the docs, but just found that it works