I am trying to fetch friends' list in Facebook SDK 3.8 but it returning Empty User List.
I have also set the permissions of user_friends. Please see the following code.
<code>
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("user_friends"));
Request request = Request.newMyFriendsRequest(session, new Request.GraphUserListCallback() {
#Override
public void onCompleted(List<GraphUser> users, Response response) {
Log.i("activitytag", "UserListSize: " + users.size());
}
});
request.executeAsync();
</code>
I am getting the UserListSize to 0. What am I missing?
If you created your app after April 30, 2014, then you're using version 2.0 of the graph API, in which case the newMyFriendsRequest will only return friends who are also using your app. You should also update your SDK to the latest (3.14.1).
In facebook api v2.0 has no way to get all friends list.
but if you want to get all friend list ONLY IN GAME then you can call
Either
Invitable Friends List:
you may use the https://developers.facebook.com/docs/graph-api/reference/v2.0/user/invitable_friends API.
OR
Taggable Friends List:
the https://developers.facebook.com/docs/graph-api/reference/v2.0/user/taggable_friends
for more detail please read facebook change log:
Facebook Change log
Related
I am having an error in Android facebook app invite. Everything was working fine. I switched the account from Facebook and now I am getting this error.
if(AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(VPPreferences.getString(VPPreferencesKeys.INVITE_SCREEN_URL_FOR_FB, ""))
.setPreviewImageUrl(getString(R.string.invite_fbimage_url))
.build();
AppInviteDialog appInviteDialog = new AppInviteDialog(this);
sCallbackManager = CallbackManager.Factory.create();
appInviteDialog.registerCallback(sCallbackManager, new FacebookCallback<AppInviteDialog.Result>() {
#Override
public void onSuccess(AppInviteDialog.Result result) {
ToastNotificationUtil.showMessageToast(InviteSelectorScreen.this, getString(R.string.invite_succ));
}
#Override
public void onCancel() {
ToastNotificationUtil.showMessageToast(InviteSelectorScreen.this, "Invite canceled");
}
#Override
public void onError(FacebookException e) {
ToastNotificationUtil.showMessageToast(InviteSelectorScreen.this, "Invite failed ");
}
});
appInviteDialog.show(content);
}
Quoting from Facebook Developers there is a major change in their policy.
As of November 7, 2017, link customization is available however the
link must be owned by the posting page and a page access token is
required.
To verify ownership, check the
ownership_permissions{can_customize_link_posts} field on the URL node.
You must call this endpoint before posting new links.
Without this
step, custom link page posts will not work for un-scraped links. See
our Link Ownership Guide for more information.
For versions 2.10 and
lower, picture, name, thumbnail, and description are deprecated.
caption is deprecated for all versions.
Please go to the given link and change check the ownership_permissions{can_customize_link_posts} field on the URL node.
Hope this helps
I had the same issue Hamza, what I found is this:
As the latest release of Facebook SDK version 4.28.0 - November 7, 2017, App Invites is deprecated. https://developers.facebook.com/docs/app-invites/android/
With the release of the Facebook SDK version 4.28.0, App Invites is
deprecated. It will be supported until February 5, 2018.
I think the solution is to use another way to allow your users share your app with its friends like firebase dynamic links.
Hope it helps
I have updated my Android Facebook SDK to 2.3 and I can't use FQL requests anymore.
How can I have get my "friendsrequests" through a Facebook Graph API request ?
What solutions I have ?
Thanks for your help
UPDATED ANSWER
This is **deprecated**, you cant get this anymore
The Documentation says /me/friendrequests was removed after Graph API 1.0
This document refers to a feature that was removed after Graph API
v1.0.
/* make the API call */
new Request(
session,
"/me/friendrequests",
null,
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
}
} ).executeAsync();
Permissions
A user access token with read_requests permission is required to view
the current person's received friend requests.
Graph explorer says
{
"error": {
"message": "(#12) friend requests is deprecated for versions v2.0 and higher",
"type": "OAuthException",
"code": 12
}
}
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.
I am developing an application in which I am using Facebook SDK for different purposes. Currently I have implemented Login through Facebook. Now my next task is to fetch all the photos of the logged in user and display all of them in a grid. I am following the official facebook developer website as a reference for this task. Following is the code that I am using to fetch the user photos.
new Request(
Session.getActiveSession(),
"/me/photos",
getRequestParameters(),
HttpMethod.GET,
new Request.Callback() {
public void onCompleted(Response response) {
/* handle the result */
Log.d("Response ","Response " + response);
mpBar.setVisibility(View.GONE);
}
}
).executeAsync();
private Bundle getRequestParameters()
{
String accessToken = LoginSigbUpCustomerNew.mytoken;
Bundle parameters = new Bundle(1);
parameters.putString("access_token", accessToken);
return parameters;
}
Here, I am getting response like this :-
{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}
I cant understand why the data array is empty. Also I am requesting the user_photos permission from user. So where the thing is wrong.
I am new to this Facebook SDK and dont know how to solve this. If anyone can help me it would be great.
Thanks in advance.
Your code to request your photos is just fine according to the documentation of Facebook SDK however I think that you forgot to request permission from the user who's logged in (you in this case).
Copied from Facebook SDK documentation: A user access token with user_photos permission is required to see all photos that person is tagged in or has uploaded.
The following link gives you a small tutorial on how to add access tokens to the login button: https://developers.facebook.com/docs/android/login-with-facebook/v2.2?locale=en_GB#step3
In your case it would be (code snippet is for activities only, for fragments: click the url above and follow the tutorial there. Pretty straight forward):
...
LoginButton authButton = (LoginButton) findViewById(R.id.ID_OF_YOUR_LOGIN_BUTTON);
authButton.setReadPermissions(Arrays.asList("user_photos"));
...
In your overriding onCreate method.
Method two:
...
Session session = Session.getActiveSession();
if (!session.isOpened() && !session.isClosed()) {
session.openForRead(new Session.OpenRequest(this)
.setPermissions(Arrays.asList("user_photos"))
.setCallback(YOUR_CALLBACK_CLASS_VARIABLE));
} else {
// Open an active session. Basically happens when someone is already logged in.
}
...
Before making the call to request all the user photos, you can simply open a new request when the user hasn't logged in yet. This can happen in View.OnClickListener class of a Button as it seems that you're not LoginButton of Facebook.
YOUR_CALLBACK_CLASS_VARIABLE is your class implementing Session.StatusCallback. I'm quite certain you know what it is and what it does.
Method three:
...
Session.NewPermissionsRequest newPermissionsRequest = new Session
.NewPermissionsRequest(this, Arrays.asList("user_photos"));
session.requestNewReadPermissions(newPermissionsRequest);
...
When the user is already logged in (so after the user is logged in) and you wish to request additional permissions from the user to access his photos or whatsoever. This is by the way all written in the docs of Facebook SDK for Android.
For more information: https://developers.facebook.com/docs/android/login-with-facebook/v2.2?locale=en_GB#step3
If the request returns an empty result, check whether the used Access Token contains the user_photos permission:
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/photos#readperms
You can inspect the Acces Token via
https://developers.facebook.com/docs/facebook-login/access-tokens#debug
Request:
GET /debug_token?
input_token={input-token}&
access_token={access-token}
I am getting a wrong Facebook Friend Id: I am getting some long alphanumeric value in id which, among the other things, is also not unique (e.g. it changes on each call).
Actually I want to use this id as a unique identifier to login, but since it changes every time is not so helpful.
So what's wrong here? What else can I do for unique identification? Any suggestion will be appreciated.
I am using this code to get friend list:
Bundle required = new Bundle();
required.putString("fields", "uid, name, picture.type(square), gender, email");
//Request for friendlist from facebook
Request req = new Request(session, "me/taggable_friends", required, HttpMethod.GET,
new Callback() {
#Override
public void onCompleted(Response response)
{
is2=response.getGraphObject();
JSONObject json = is2.getInnerJSONObject();
readResponse(json);
String str = json.toString();
saveFileOnSD("data", str);
// generateNoteOnSD("frinedresponse", str);
Log.v(TAG, str);
}
});
Request.executeBatchAsync(req);
The problem is that you are using taggable_friends. Taggable_friends are for if you want to tag friends. It is by design that the id changes every single time you call it.
If you want friends you should use /me/friends but it will only return friends that are already using the app.
Depending on what you need all friends for some solutions can be found here: https://developers.facebook.com/docs/apps/faq
On 30th April 2014 facebook make so many changes, so if you create you facebook APP ID after this date you can't get facebook id of your friend with taggable_friend, so for getting facebook id of your friend you need to use "me/friends instead of me/taggable_friend", but you get only those friend list who are using your app.