I have tried using the code below and if add old facebook sdk it workd fine but new sdk I get only the friend who is on app.How can I get the list of all friends in new sdk? .I really appreciate any help .Thanks in Advance.:
new Request(
MainActivity.facebook.getSession(),
"/me/friends",
null,
HttpMethod.GET,
new Request.Callback() {
#Override
public void onCompleted(Response response) {
/* handle the result */
Toast.makeText(activity, response.toString(), 5).show();
}
}
).executeAsync();
Short Answer: You CanĀ“t.
Since v2.0, you can only get the friends who authorized your App too, for privacy reasons. An App should not know about anyone who does not use the App.
If you want the names to tag them, there is taggable_friends. If you want to invite them, use invitable_friends. But check out the docs for their limitations.
Related
I'm currently researching facebook sdk.
I have googled around and just found some tutorial with like button for pages and haven't seen any tutorial for like button for posts.
So does facebook sdk 4.+ allow us to make an action like post?
If it does, can you guys show me some example please?
Thanks guys!
It's all written in the documentation:
Note: as of Nov 17, 2016 we changed the behavior of publishing likes and only support this action with Page Access Tokens.
https://developers.facebook.com/docs/graph-api/reference/v2.8/object/likes
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/{object-id}/likes",
null,
HttpMethod.DELETE,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}
}
).executeAsync();
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How do I get the full friend list of a person, using Android Studio and Facebook SDK 4.4.+. I have looked for tutorials everywhere but they are all out dated. I just need a simple code without installing any new libraries and I need some more explanation with the code
Straight from Facebook API Docs - https://developers.facebook.com/docs/graph-api/reference/v2.4/user/friends
This will only return any friends who have used (via Facebook Login) the app making the request.
If a friend of the person declines the user_friends permission, that friend will not show up in the friend list for this person.
This was something Facebook API did to us when they enforced v2 upon all apps.
Thanks Facebook.
Does that sound like you? Well you found the right question!
What you will need to perform the "Friend getting" is the Facebook Graph API. Facebook has a pretty good explanation on how to use their Graph API + you can test it with their Graph Explorer.
But may be you need more help? Well I can give it to you.
First integrate your Facebook SDK properly and add a log in button, so the person can Login.
From here on now comes the Graph API. I recommend you read the Graph API documentation and the list of permissions after you read this answer to understand this amazing tool even better.
Many say that after a certain update a while ago you cannot get a full friends list. Well they are partially correct. Facebook did change how some commands behave, but others are still at your dispolsal. For example the /taggable_friends
The taggable friends will give you an array of names that are all of your friends, who have not made their profile private. For example I have 409 friends, but this function shows them to me only up to the 406 person, because 3 have private accounts.
How to use the taggable_friends?
In the Log in code add this:
GraphRequest requestet =
new GraphRequest(
accessToken,
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject obj = response.getJSONObject();
JSONObject sum;
try {
sum = obj.getJSONObject("summary");
c=Integer.valueOf(sum.optString("total_count"));
fff.setText(sum.optString("total_count"));
} catch (JSONException e) {
e.printStackTrace();
}
}
}
);
GraphRequest requestt =
new GraphRequest(
accessToken,
"/me/taggable_friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
JSONObject obj = response.getJSONObject();
JSONArray arr;
try {
arr = obj.getJSONArray("data");
JSONObject oneByOne = arr.getJSONObject(1);
lmaYOLO.setText(Integer.toString(c)+" "+oneByOne.opt("name").toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
}
);
Bundle parameters = new Bundle();
parameters.putString("fields", "name");
requestet.executeAsync();
request.setParameters(parameters);
request.executeAsync();
requestt.setParameters(parameters);
requestt.executeAsync();
The first graph request that we use is the "requestet" what I do in there is get the number of friends of the logged in user, using the friends node.
In order to access any node you need to use JSONObject objname = previousobject.getJSONObject("name of node")
with objname, previousobject and name of node being changable according to your needs.
With taggable_friends it is more tricky, as you will get an Array of objects, each of which will contain a name of a friend. So you can see at the code how I get an Array same as the Object. Now at JSONObject oneByOne = arr.getJSONObject(1), the one is changable to any number of your friends list (REMEMBER arrays start from 0, so the first element will be getJSONObject(0)).
Now from here you can create a while loop, which will go from 0 to the number which we got from the /me/friends
You might have noticed that when I setText I use oneByOne.opt("name"). What opt does is GET the value of that node (in our case the name of the friend), unlike the getJSONObject, which opens the node.
Starting this program I will see on my screen appear:
406 - the number of non-private friends
Biggus Dickus - the second friend in my Facebook list (which is certainly not your Real life second friend).
Changin it to give me my first friend (remember you had to put 0),
I will get
407 (oh I accepted a new friend's request)
Martin Luther King
From here on you can do whatever you want with this code! Have Fund
You cannot get the whole friend list. Only those which are also using your app.
See:
https://developers.facebook.com/docs/apps/upgrading#upgrading_v2_0_user_ids
I'm building an application to get the unread notification count for social medias (facebook, twitter)
Before api 2.4 what I'm suppose to do is to get permission from user to get their notification then do a
FBCount= new GraphRequest(AccessToken.getCurrentAccessToken(),
"/me/notifications?fields=unread",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result */
}).executeAsync().toString();
But at api 2.4 it seems like it's impossible to get it anymore ?
Is there any possible way to the number of unread messages ?
No there is no way in v2.4. If you read the changelog https://developers.facebook.com/docs/apps/changelog you will see it was removed.
I'm trying to discover if a user likes a specific facebook page by using Graph API inside an android application using the FB SDK v3.
The following call works and reports all of the likes of the user along with every other detail to do with each resulting item.
Request.executeGraphPathRequestAsync(session, "me/likes", new Request.Callback()
Since I'm not interested in any peripheral data, I just want to get the id back so I can lookup the page I'm interested in, but when I add the parameters as follows...
Request.executeGraphPathRequestAsync(session, "me/likes?fields=id", new Request.Callback()
... no object is returned from the call. If I post the same queries in the Graph API explorer they give back the expected results.
In addition to this question, is it at all possible to limit the result of the query to just the page ID to begin with, since I already know that piece of information? I have no use for the rest of the data being returned and would prefer not to chew up user bandwidth unnecessarily. I've searched high and low and it doesn't seem possible. Even the FQL explorer doesn't work when trying to limit by both user and page iD as the example suggests. I get an empty result set when adding 'AND page_id=xxx' to the query.
As far as i know, you cant run queries with field in 'executeGraphPathRequestAsync'.
instead use 'Request' and run in with 'RequestAsyncTask'.
Short example:
String grapPath = "me/home";
Bundle params = new Bundle();
params.putString("fields", "type,id,object_id,created_time,from,picture,likes");
params.putString("limit", "500");
Request request = new Request(session, grapPath, params, HttpMethod.GET, new Callback()
{
#Override
public void onCompleted(Response response)
{
if (response != null)
{
Log.d(TAG_NAME, "response: " + response.toString());
}
}
});
RequestAsyncTask task = new RequestAsyncTask(request);
task.execute();
Hope i managed to help you :)
The Facebook SDK will add the "?access_token" to the end of the graph path string. So the graph command ends up looking like:
me/likes?fields=id?access_token
Break out the fields into a params Bundle.
Found this issue resolved in a Facebook bug post:
http://developers.facebook.com/bugs/314504765319932?browse=search_5116b87d245900257505334
Ok so I have been researching the facebook api and Noticed that they released a new SDK. I have been trying to implement a checkin to a known place id.
I have seen posts that use the facebook.request("me/checkins", params, "POST"); to checkin using the facebook instance.
I realize that checkins are depreciated and that i should be posting with a location/place id instead. The problem comes when i want to search for all of my friends that have been to that location within that past 24 hours. I do not want to filter through all of my friends posts to retrieve the ones with my known locations.
With checkins i simply made a call to the placeid/checkins and filtered out all checkins that were too old to matter.
Has anyone gotten checkins to work using Request?
Is there a graphpath that will allow me to post a checkin to a place? me/checkins perhaps?
I am trying to use something like Request(session, "me/checkins", parameters, POST) But i have been unsuccessful so far.
If there is not a way to do this with Session and Request then do Facebook and asyncFacebook runners work well with SSO?Can they be mixed?
This is my code to post a checkin.
params.putString("place", "166793820034304");
params.putString("message", "checking in "
params.putString("coordinates", "{\"longitude\":-122.1477782,\"latitude\":37.48566}");
Request.Callback callback6 = new Request.Callback() {
public void onCompleted(Response response) {
// response here
}
};
Request request6 = new Request(session, "me/checkins", params, HttpMethod.POST, callback6);
RequestAsyncTask task6 = new RequestAsyncTask(request6);
task6.execute();