Facebook Friends Request - Missing Friends - android

I am requesting to get user friends from an Android App that I am developing. As from Facebook Api V2.0 I know that I should get only user friends that have already logged in through my App. However, although I know certain friends of a user have logged In through my App they do not appear in Facebook Request Response when requesting friends of that user. For example I get back 40 friends rather than 50+.
Has anyone experienced this behavior before? I already deleted app from few users to re-authorized it through login but I haven't see any change in the behavior.
Here is the code I'm using:
new Request(ParseFacebookUtils.getSession(),"me/friends", null, null, new Request.Callback(){
#Override
public void onCompleted(Response response) {
if (response == null){
return;
}
else if (response.getError() != null){
response.getError().getException().printStackTrace();
return;
}
GraphMultiResult result = response.getGraphObjectAs(GraphMultiResult.class);
List<GraphObject> fbInList = result.getData();
if (fbInList != null && !fbInList.isEmpty()){
for (GraphObject user : fbInList) {
JSONObject jsonUser = user.getInnerJSONObject(); // The Facebook User
System.out.println("name: " + jsonUser.optString("name"));
}
}
}
}).executeAsync();

I've found what was the problem. When I updated to the latest Facebook SDK, Facebook was returning only 25 friends. I needed to use paging or add a limit to my Friend Request. On previous SDK I didn't need to.
Adding limit:
Bundle params = new Bundle();
params.putString("limit", "50"); // Up to 5000?
friendRequest.setParameters(params);
Relevant Stack Overflow Questions:
Facebook graph API 'friends' request now only returning 25 friends per page? What's going on?
newMyFriendsRequest Facebook returns only 25 friends
Useful Facebook link for paging:
https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#paging

The relevant portion of the doc for you is this
In v2.0 of the API I'm unable to get the full friend list of someone who has logged into my app - is there a way to get the full friend
list?
With Graph API v2.0 and above, calls to /me/friends return only the
friends who also use your app. These friends must have also granted
the user_friends permission. In the cases where you want to let people
tag their friends in stories published by your app, you can use the
Taggable Friends API. If you want to invite people to your app, we
have a number of solutions that depend on the type of app you've built
and the platforms you've built for. Please see our question about
Inviting Friends for more information.
So along with only friends using your app, they should also have authorized user_friends otherwise you wont get their details. Have you done this?

Related

Facebook graph API /me/friends not returns all friends who authorized app?

After a long surf i have realized Graph API /me/friends only returns the person's friends who also use the app.anyway i need answer from an experienced one
Any possibility to fetch all friends of a user ?
Now my second query I have used the following code for fetching friends of a user after verifying and approved user_friends permission by team facebook and also I'm logging in with the user_friends permission.
/* make the API call */
new GraphRequest(
AccessToken.getCurrentAccessToken(),
"/me/friends",
null,
HttpMethod.GET,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
/* handle the result *
}
}
).executeAsync();
Response
{Response: responseCode: 200, graphObject: {"summary":{"total_count":572},"data":[]}, error: null}.
I have friends in my list whose also uses the same app but ain't get their information also you can see in the above response only total_count were returning.
What's going wrong, Can anyone help me out ?
Update
After some debugging now I'm getting only details of single friend in response while i have friends more than that whose using the app.why it won't return the other friends details ? any idea ?
Also when i debugged with Access Token Debugger, it tells that the user have user_friends scope.still ain't get the expected response.
If you are updating permissions in an existing application then exiting users will have to logout and login again with new set of permissions with new code.

Publishing Facebook (v2.3) comment on friends post from Android

After a few days of frustration, I would kindly ask for your help [also apologies as I am very new to FB]. I have an Android app in development, it has a Facebook app id, keys, hashes, etc. I created 4 test users for (obviously) test purposes and made all of these friends and users of the app. The app is set for v2.3 API. I see the increasing restrictions that Facebook is imposing, but I still think that I can do what I need to do ...
On login on the mobile, after the 'two-step' login with simple permission and then ask for more, I ultimately have these permissions:
user_friends
user_posts
manage_pages
publish_pages
publish_actions
public_profile
For a (test) user of the app, that has not yet logged into the app and has therefore not yet granted any permissions, when I query
/v2.3/{user-id}/feed or /v2.3/{user-id}/posts
I get a "200" (non-error) JSON response with no data, from memory its something like this:
{
"data" : [
]
}
which agrees with the documentation as given in FB docs
where it says:
If you attempt to read data from a feed that your app has not been authorized to access, the call will return an empty array. OK, so all that makes sense.
So then I get a list of messages from a friend (test user at this point) and store their message ids, it looks like they are in the form: userid_postid and I can scan the text, great. I use API v2.3 which looks like it will close in July 2017, but it works now.
OK, so now I want to post to the users wall or page or something that FB calls it - is it true that I can't do this anymore? I next tried to post to the comments of the stored user_postid but this fails with:
{HttpStatus: 403, errorCode: 200, errorType: OAuthException, errorMessage: (#200) Permissions error}
I do think I should have the permission to do this. I do notice that there is no comment widget on the test users posts - is that the problem? Do some posts not have comments at all, or is this a function of test users only? Here is what the posts look like, note there is no comment line shown:
I've come a long way, and can do quite a bit (get posts, user pics, friends that use the app - despite FB's documentation) but am now stuck. Any help or pointers greatly appreciated.
EDIT, forgot the code for the attempted publish to a comment:
params.putString("message", someText);
new GraphRequest(
// version 2.3 will work until July 8, 2017
AccessToken.getCurrentAccessToken(),
"/v2.3/" + mFacebookPostId + "/comments",
params,
HttpMethod.POST,
new GraphRequest.Callback() {
public void onCompleted(GraphResponse response) {
mSends++;
FacebookRequestError err = response.getError();
if (err == null || err.getErrorCode() == 0) {
mSendGood++;
}
tv_status.setText("Sent " + mSends + " posts, " + mSendGood + " good");
}
}
).executeAsync();
Update: am I supposed to get a 'page access token', again the FB docs are not clear?
The answer seems to be a bug with the Facebook Test Users. I was never sure if I could do what I wanted to do as this was a first FB development for me, but started to get suspicious when I saw that Test User's posts do not have comments or like buttons.
But now I am not sure how to test this code, as real users can't use the app in development mode?

Facebook SDK android, get connected accounts

A facebook user can control multiple pages. For example, a user can have their personal facebook account, their public figure page and their business page. This shows up as three distinct accounts with their own User information in facebook's server.
I want to list these things, how can I retrieve what these accounts are using the Facebook SDK?
I feel like it has to do with the Request.newMeRequest method, but this returns a GraphUser object.
and the Request.newMyFriendsRequest returns a list of users, but not a list of the personal account's connected accounts.
edit I am now using this
new com.facebook.Request(
session,
"/me/accounts",
null,
HttpMethod.GET,
new com.facebook.Request.Callback() {
#Override
public void onCompleted(com.facebook.Response response) {
if(response!=null && response.getGraphObjectList()!=null){
}
}
}
).executeAsync();
but response is null. My session has the manage_pages permission requested as well
edit I tried replacing "/me/accounts" with "/"+userId+"/accounts" and I still get back a null response. Baffling.
Insight appreciated
You can test this procedure at Graph Api Explorer -> Just click on 'Get Access Token' button-> under 'Extended permission' check 'manage_pages' & submit it. It will give you the admin-page-details JSON.
And please see Graph API Reference /{user-id}/accounts

Unity facebook API FB.API() java.io.FileNotFoundException

I ran into a problem. I am using Unity facebook SDK and FB.API to post on user feed.
The Code I am using is:
if (FB.IsLoggedIn) {
var data = new Dictionary<string, string>() {{"message", "I just scored "+score+" in GameName. Download it now!"}};
FB.API ("/me/feed", HttpMethod.POST,LogCallback, data);
}
void LogCallback (FBResult result) {
if (result.Error != null) {
print ("score submission failed with error= "+result.Error.ToString());
}
else {
print ("score submitted with result= "+result.Text.ToString());
}
}
and the result I am recieving is:
score submission failed with error= java.io.FileNotFoundException: https://graph.facebook.com/me/feed
I searched on the net and found that perhaps it has something to do with
publish_actions
permission. But I am using this permission.
I then went to the see the app on Facebook Developers and went to Status and Review.
There Approved permissions are:
email, public_profile and user_friends
I then tried to add
publish_actions
permission but it showed the error that I am missing icon, long description and privacy policy URL.
It wants to submit app for review. Am I doing everything correct? Do I need to upload android apk for them to review?
Can someone guide me? Thank you
You need to ask for publish_permissions from FB.Login first in order to use the /me/feed. (you'll see a message "this app wants to post on your behalf...")
That said:
Using the graph API to post a message to a user's feed if the user hasn't explicitly clicked a button indicating they want it to happen is known as 'implicit shares' and is discouraged.
Using a message you create in code instead of letting the user type in their own message is known as "pre-filling" and is not allowed by Facebook policies.
You don't need publish_actions if you use the Facebook dialogs instead of the graph API.

How to authorize my app through facebook and fetch facebook user information using Facebook SDK 3.0

I am able to login to facebook from my app by integrating Facebook latest SDK i.e. 3.0
But now I want to fetch user information and I am not able to find a way to do so. All links I am getting from google and stack is for the old version of facebook sdk. Also I would like to know how to authorize an app through facebook.
In older versions we were doing it by:
Facebook facebook = new Facebook(appId);
But these things are deprecated in sdk 3.0.
Please can anyone help me out on these issues or provide links having good tutorials or sample examples!
Thanks
Once you have an open session you execute a new me request.
Session session = Session.getActiveSession();
if (session != null && session.isOpened()) {
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
if (response.getError() == null){
//Do what you want with the user object
}
else {
//Do something with the error
}
}
}
});
}
As said on facebook developers page : "the user data you can access depends on the permissions a user has granted your app along with the data a user has chosen to share with apps."
So you have to add the needed permission in respect to what specific fields you want.
For the app authorization you should follow the Create a Facebook App section for the Facebook SDK for android.
But if you already have a working login you shouldn't need further operations.

Categories

Resources