Facebook friend list in Facebook Android SDK 3.14 - android

I am trying to get friend list using Facebook Android SDK 3.14 but getting no results. Some pointed out that friends who are using my app can only be retrieved but I want to retrieve my complete friend list. Can anyone please tell me how can i achieve that?
I am using the following code:
<code>
Request.executeMyFriendsRequestAsync(session, new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
// TODO Auto-generated method stub
Log.i("mustang", "response; " + response.toString());
Log.i("mustang", "UserListSize: " + users.size());
}
});
Thanks,

new Request(
session,
"/me/friends",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}).executeAsync();
Permission: A user access token with "user_friends"
permission is required to view the current person's friends.

Related

Facebook SDK for Android GraphUser

I am able to access the id, firstname, lastname, gender, and email of a GraphUser by using the following code.
But, I also need access to "location", "number of friends", "basic info" and "work company". How can this be done? I have tried other stackoverflow links, and checked the Facebook SDK link, but not getting a break through. Could I be provided code to directly access the required fields in the same way as the data that I already have?
What other permissions would I need?
loginBtn.setReadPermissions(Arrays.asList("public_profile", "email", "user_friends", "user_birthday", "read_friendlists"));
loginBtn.setUserInfoChangedCallback(new UserInfoChangedCallback() {
#Override
public void onUserInfoFetched(GraphUser user) {
if (user != null) {
login_text.setText("Please login to continue");
userDetails = new JSONObject();
try {
Log.d("user birthday", user.getBirthday());
userDetails.put("fbId", user.getId());
userDetails.put("firstName", user.getFirstName());
userDetails.put("lastName", user.getLastName());
userDetails.put("gender", user.getProperty("gender").toString());
userDetails.put("email", user.getProperty("email").toString());
} catch (JSONException e) {
Log.d("Error: ", "Error setting user settings in FBActivity");
}
} else {
//login_text.setText("You are not logged");
}
}
});
EDIT:
I got everything except the total number of friends an individual has. How can that be done. I have gone through your links and it seems that I need to call another GraphRequest link. But I don't that. I want the total number of friends (no names, no details, just the number). I have added the permission "user_friends". What code should I write to get the number?
This is a pretty straightforward answer and the facebook documentation covers these details. https://developers.facebook.com/docs/reference/android/current .
https://developers.facebook.com/docs/graph-api
Here is the answer anyway!
You will need user_friends for the number of friends. It returns the total count of friends.
The default permission set called "basic info" has been removed, and replaced by "public profile".
user_location for location.
user_work_history for the work company.
please note : users can choose to not give these permissions to your app, in which case you should handle those scenarios properly, else your app will get rejected in the review process.
To get number of friends please refer to the following link:
https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
Permissions needed would be: user_friends, which you already have included..
You'll get friends count in field 'summary' in the name of total_count
Similar question: facebook api on android - how can I get the number of friends that a user has?
loginBtn.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
new GraphRequest(
loginResult.getAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
Log.i("response", response.getJSONArray().toString()); //find the summary 'total_count' in the response
}
}
).executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
}
});

How can we see users’ information through Facebook Graph API in Android?

I am making a dating app (android) by using Facebook API (You know the similar application that starts with tin…)
Anyways, I registered my application in Facebook developers and I also got approval to use functions that I need through 'Submit Items for Approval'(my Approved Items: email, public_profile, User_photo, User_like, user_work_history, user_education_history )
So, I can log in from my app using my Facebook ID and I can also see users’ basic information too.
But! The main problem is that I cannot see photos (except public_profile) even though I was approved for this.
So I really need someone’s help. Please help me!
It will be great if you can review the code I used (To use when looking at users’ photos)
new Request(Session.getActiveSession(), "/{user-id}/albums", null, HttpMethod.GET, new Request.Callback() {
#Override
public void onCompleted(Response response) { }
}).executeAsync();
Hey Use the following code. It works perfectly for me.
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "photos.limit(100)");
request.setParameters(parameters);
request.executeAsync();
Try the above code and you will get a jsonobject which can be used to get the image URLs. To know the response you get. Try Graph API explorer. The response format will be the same.
https://developers.facebook.com/tools/explorer
if you would like to get the photos of a user try the following code. Please note that you need the user-id to they photos
new Request(
session,
"/{user-id}/photos",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
Please refer to https://developers.facebook.com/docs/graph-api/reference/user/photos/
You can use facebook graph api for accessing user info
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
}
});
To call this method, use below line,
request.executeAsync();
For additional info visit facebook official documentation
https://developers.facebook.com/docs/android/graph

Create a Request in Facebook SDK 4 (Android)

As I understand, Facebook SDK v4 doesn't use the Session anymore, but I read in their Graph API document, the session is still used to create the Request
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.3
/* make the API call */
new Request(
session,
"/me",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
It's confusing me, and how can I get the session for Request? Any latest example to get the user profile data by using Facebook Graph API?
Any advice is appreciated.
On facebook developers' page is published a changelog and upgrade post. In your case this would be an option:
GraphRequest request = GraphRequest.newMeRequest(accessToken, new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject user, GraphResponse response) {
/* handle the result */
}
}).executeAsync();
By the way, they specify this:
By default a newMeRequest method fetches default fields from a user object. If you need any additional fields, or want to reduce the response payload for performance reasons, you can add a fields parameter and request specific fields.
For example:
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();
I hope my answer helps you, being this one my first answer in stackoverflow. Greetings.
Reference: Facebook Android SDK Upgrading

how to get a list of all user friends (not only who use the app)?

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

Get Posts data from facebook in android

I want to get all the posts of my facebook account wall in android. I have got session but when I execute the below query then it gives an error.
new Request(fbSession,"/me?fields=posts",null, HttpMethod.GET, new Request.Callback()
{
public void onCompleted(Response response) {
ShowToast(response.toString());
}
}).executeAsync();
Error:
Active Access Token must be used to query information about the current user
Although I have an active session variable, which can retrieve my basic information
1) It means you don't have an access token or access token does not match the current logged in user.
2) You have an expired or non-working access token (perhaps left over from the last time you used the app?). You could try clearing that out and re-authenticating.
3)
if (state.isOpened())
{
new Request(fbSession,"/me?fields=posts",null, HttpMethod.GET, new Request.Callback()
{
public void onCompleted(Response response) {
ShowToast(response.toString());
}
}
).executeAsync();
}
for more info see below link:-
http://www.androidhive.info/2012/03/android-facebook-connect-tutorial/
https://developers.facebook.com/docs/android/getting-started/

Categories

Resources