I implemented this code from the Facebook SDK to get mutual friends.
Bundle params = new Bundle();
params.putString("fields", "context.fields(mutual_friends)");
// make the API call
new Request(
session,
"/{user-id}",
params,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.d("results", response.toString());
}
}
).executeAsync();
How do i read the Response object and retrieve the total count and the list of mutual friends? I have successfully gotten the result in the log.
Thanks.
Booth people need autorize your friend_list_permission to you see the users in common. If not you need use all_mutual friends, but you just can run this in server, no working in clients. look documentation in all_mutual_friends.
I explain this post here.
https://stackoverflow.com/a/34663235/3516549
Related
I am using Facebook android SDK (V4) to post a message on Facebook using "me/feed" graph API.
Bundle params = new Bundle();
params.putString("message", message);
new GraphRequest(
token,
"me/feed",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
//Handle response
}
}
).executeAsync();
This is working fine.
Now I want to add feeling/Activity in my post.
I have search on Google but haven't found any solution on that.
Does anybody know of a way?
Thanks in advance.
My Facebook app's Status and Review feedback suggests not to pre-fill text while posting on wall. But I can found the use of message param in the Facebook Graph API documentation Graph API Publishing section.
Bundle params = new Bundle();
params.putString("message", "This is a test message");
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/feed",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
I have verified it and it works fine. Is it allowed as per updated Facebook policies ?
The message must be 100% user generated, so if you present an (EMPTY!) input field where the user can enter the message before you do the API call, it´s fine. Prefilling means that you prefill the message or the input field, which is not allowed.
https://developers.facebook.com/docs/apps/review/prefill
I am trying to get the posts from a page including all the pics related to the post.
I am able to get one picture from the post using object_id, but I need the other photos as well.
object_id returns only one Id which is the first photo's ID.
Please help.
GraphRequest greq =
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{page-id}/posts",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONArray data = null;
}
}
);
Bundle params = new Bundle();
params.putBoolean("redirect",false);
params.putString("fields", "object_id");
greq.setParameters(params);
greq.executeAsync();
The data should be in the attachments field. In the subattachments sub-field specifically.
You should test this in the Graph API Explorer to see the API response and update your Android implementation based on that.
In my App i am integrating facebook SDK 4.5.0.
To fetch details of user I am using method
GraphRequest request = GraphRequest.newMeRequest
In user json response i am getting wrong user id.
In case of IOS for same application and same user i get correct userId.
Can anyone help me to solve this?
This is my Code to fetch user details:
GraphRequest request = GraphRequest.newMeRequest(com.facebook.AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject user, GraphResponse response) {
if (user != null) {
doLoginFb(user);
}
}
});
request.executeAsync();
After V2.0API user id is "app-scoped" so the id can be different for same user on different apps.
You can refer to the documentation here for more details.
It also says this :
No matter what version they originally used to sign up for your app,
the ID will remain the same for people who have already logged into
your app. This change is backwards-compatible for anyone who has
logged into your app at any point in the past.
If you're not mapping IDs across apps, then no code changes should be required.
Get some public profile of user:
Bundle params = new Bundle();
params.putString("fields", "id,name,email");
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me",
params,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
try {
Log.e("JSON",response.toString());
JSONObject data = response.getJSONObject();
//data.getString("id"),
//data.getString("name"),
//data.getString("email")
} catch (Exception e){
e.printStackTrace();
}
}
}
).executeAsync();
here is the facebook sample
Bundle params = new Bundle();
params.putString("source", "{image-data}");
/* make the API call */
new Request(
session,
"/me/photos",
params,
HttpMethod.POST,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
}
).executeAsync();
what is {image-data}
I tried use byte[].toString, file.toString, path of file. not work.
so how to upload photo with this api?
facebook doc is wrong.
change
params.putString("source", "{image-data}");
to
params.putByteArray("source", "{image-data}");
If you want to post a photo, use one of the Request.newUploadPhotoRequest methods, it will set everything up for you.
See https://developers.facebook.com/docs/reference/android/current/class/Request/#newUploadPhotoRequest