Facebook API - getting friend list with detail info again - c#

I'm using Facebook SDK ( http://facebooksdk.net ) and want to get friend list with the following information:
1. ID
2. Name
3. Photo
4. link
5. Email
6. etc...
I have read Facebook's documentation and different posts of forum (including stackoverflow), but I'm confused. After it I'm not sure, is it possible to get this information by API request or not. First at all, this request returns only ID and name data:
var client = new FacebookClient("XXX");
dynamic friends = client.Get("/me/friends");
Next step - try to modify this request to specify returned fields:
var client = new FacebookClient("XXX");
dynamic friends = client.Get("/me/friends?fields=about,bio,age_range,first_name,gender,address,email,location,link,languages,username,last_name,timezone,updated_time");
it returns only some fields:
"first_name": "XXX",
"gender": "male",
"link": "https://www.facebook.com/XXX",
"username": "XXX",
"last_name": "XXX",
"updated_time": "2013-09-07T12:18:34+0000",
"id": "XXX"
is it possible to return more fields? As I understood, it depends on permissions. I try to set these permissions. I go to Applications -> MyApp -> Permissions, and see, that field "User & Friend Permissions" is empty. I try to set some permissions, i.e.
user_about_me,friends_about_me
and after click "Save" button I see the message:
Changes saved. Note that your changes may take several minutes to
propagate to all servers.
but field "User & Friend Permissions" is empty again. First question : why and how can I see all set permissions?
secondly - I don't see any changes in my request via FacebookClient (but field "About" is added to request). Why?
Thanks

The fields that you can get without any extra permissions:
first_name
gender
link
username
last_name
updated_time
id
With permissions-
friends_about_me - about, bio
friends_location - location
friends_likes - languages
Invalid fields (I don't know from where you saw these)-
age_range
address
email
timezone
Another thing that you are not getting all the fields is because the permissions are not being asked by the user (and hence not granted any to your app).
This is because, you have to add the permissions in your code, while login-in the user- not just adding permissions in the App Settings.
For eg, if you are using javascript sdk, it is done using the scope parameter. Reference
You can always test your call here: Graph API Explorer

To answer your first question, you can see the answer here, use the Facebook graph api and search /{user id}/permissions.
Some clerification for the rest. You can't get friends email address as answered here. In order to get the friends profile picture you need to add the field picture (you can specify the size like this picture.width().height().
I reccomend you try to use Facebooks Graph Api Explorer to play with the permissions and the info you request.

Related

Selecting a user by ID doesn't work, but works by email

I am using the Microsoft Graph API to access some events in my company's Azure AD Outlook.
The problem I am now having is that I can not access the CalendarView (or really I can't access the user at all) when I try to specify the user with an UUID instead of an email. The strange thing is that email works just fine, but I am not allowed to store emails outside of the Azure AD, so ID would be the preferred method.
Here is the exact API call I try to make: https://learn.microsoft.com/en-us/graph/api/user-list-calendarview?view=graph-rest-1.0&tabs=csharp
But all examples only use the .Me accessor and not the .Users[{ID | userPrincipalName}]
I am quite sure that the UUID I use is correct since it comes from an API call earlier. Or does the documentation article mean something else than the user UUID by {ID | userPrincipalName}?
A room looks like this (when read as a JSON object):
{
"id": "00000000-0000-0000-0000-000000000000"
"emailAdress": "room#company"
...
}
This works:
await graphClient.Users["room#company"].CalendarView.Request(queryOptions).GetAsync();
While this does not work:
await graphClient.Users["00000000-0000-0000-0000-000000000000"].CalendarView.Request(queryOptions).GetAsync();
When using the UUID I get (IDs not shown here):
Code: ErrorInvalidUser
Message: The requested user '<UUID>' is invalid
ClientRequestId: <some ID>
I did test this with a hardcoded room id and email but also with the ID object I get from calling the roomlist in C#.
Another inconsistency I encountered is that I can read the whole list of microsoft.graph.room via a http request but not using the C# Microsoft.Graph.Auth package. Reading the data of a room I know the email from does however work.
So does this just not work and the doc doesn't say so?
Does the Microsoft.Graph.Auth package not support those kind of requests?
Or do I use a wrong ID?
Saladino
According to some test, only when I use incorrect object id of user it shows same error message as yours.
If I use another user's object id(not object id of the user do authentication), it will show ErrorAccessDenied because do not have permission.
If I use the object id which the user not exist in Azure AD(incorrect object id), it will show same error message with yours. So please check if the uuid which you mentioned is the user's object id(shown in below screenshot) in your Azure AD and please check if you input the correct format of object id in your code by Console.WriteLine(object id)

post for specific group in Facebook for new changes?

it is been few days that I can not post a message from my app to specific groups of friends in Facebook, I am using asp.net MVC, before that I was using following code to post for only one list of friends " for example: close friend" but now it always post to all friends even when I specify target group.
FacebookClient fpost1 = new FacebookClient(context.AccessToken.ToString());
fpost1.Post("/me/feed", new { message = "test message", to = "xxxxxxxxxxxxxx" });
what should be changed to post for only specific list. consider xxxxxxxxxxxx as a close friend list id.
Assuming your app is a website, the easiest way to do this is to just use the share button and let the user pick the group he wants to post to.
https://developers.facebook.com/docs/plugins/share-button/
If your app is mobile, you can use the Share Dialog
https://developers.facebook.com/docs/ios/share
https://developers.facebook.com/docs/android/share

how to post on facebook wall for specific list of users using asp.net c#?

I am trying to post on specific group of users on facebook such as (close friends, or family, or college friend...) and I used the code bellow.
code that I used:
1
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/1234567890/feed", new { message = "test post"});
note: access_token is working correctly when I am doing some job before this exception.
I put my friendlist id instead of 1234567890, that you can get it from graph .../me?fields=friendlists
it did not work and gave me this error "(OAuthException - #2) An unexpected error has occurred. Please retry your request later."
2
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/me/feed", new { message = "it is very cold.", to="1234567890"});
this one work, but it post to "only me" as target.
thank you
It looks to me that what you are doing here...
FacebookClient fpost1 = new FacebookClient(access_token);
fpost1.Post("/1234567890/feed", new { message = "test post"});
is wrong. Because I believe that 1234567890 is a user-id, right? Not a friendslist-id. According to the documentation this edge/endpoint signature goes like....
/{user-id}/feed
where user-id is obviously a user id. The documentation states that...
Most nodes in the Graph API have edges that can be published to (such as Photos or Posts). All Graph API publishing is done simply with an HTTP POST request to the relevant endpoint with any necesssary parameters included. For example, if you wanted to publish a post on behalf of someone, you would make an HTTP POST request as below:
POST graph.facebook.com
/{user-id}/feed?
message={message}&
access_token={access-token}
Notice that it says "On Behalf of Someone". My understanding is that you are publishing on behalf of someone and to do that, this someone must have requested an access_token through your application. In other words, if this user hasn't logged in to your app and generated a valid access token you cannot publish on his/her wall
POST graph.facebook.com
me/feed?message="hello"&privacy={"value": "CUSTOM", "allow": "1234567890"}
where the 1234567890 is one of friendlists id

How to filter Facebook pages by CREATE_CONTENT permission?

I have the following Graph API call: me/accounts?fields=access_token,name,id,perms that I use to get the page tokens from the user.
Now I would like to filter this by perms="CREATE_CONTENT". How can I filter this Graph API call?
I'm using the C# Facebook.net SDK. Currently I use this code:
client.Post("me/accounts", new { fields = "access_token,name,id,perms" });
Opening caveat: I do not know C#, but I regularly work with the Facebook in other programming languages.
Facebook has a number of "Publish Permissions" as part of its Extended Permissions. I'm assuming you're already requesting one or more of these permissions from your users. (I don't see a create_content listed; that's the only reason I mention it.) Let's say, for example, you requested the create_event permission from your users.
Try accumulating the Facebook User IDs into a list, and then issuing a FQL query using the Facebook SDK client for the permission(s) you're interested in:
List<int> facebookUserIds = new List<int>(1, 2, 3);
var query = string.Format("SELECT uid, create_event FROM permissions WHERE uid IN ({})", string.Join(",", facebookUserIds));
dynamic parameters = new ExpandoObject();
parameters.q = query;
dynamic results = client.Get("/fql", parameters);
The response you receive will have properties like this (here, in JSON format):
{
"data": [
{
"uid": 1,
"create_event": 1
},
{
"uid": 2,
"create_event": 0
}
{
"uid": 3,
"create_event": 0
}
]
}
Of course, 0 means permission denied, and 1 means permission granted for the App ID you're using to authenticate with the Facebook API.
Note: Users will only be returned in the response if they've previously authenticated your app (of the most basic level of permissions); but this shouldn't be an issue.
You can't directly filter this in the API, but it would be quite easy to do from c#- you're getting an ICollection from the Facebook.JSONObject response, so you can just use linq to filter it - Filtering collections in C# has a pretty good explanation of how to achieve this.

Why this api shows error message "Unknown fields: gender"?

I am using a graph api for facebook app. I am using this api
https://graph.facebook.com/<friendlist_id>/members?fields=id,name,gender&access_token=<access_token>
But it shows me error,
{
"error": {
"message": "(#100) Unknown fields: gender.",
"type": "OAuthException",
"code": 100
}
}
When I remove "gender" from the api, it works properly. So, why this api shows me this error. How to get gender of a user in this api?
Because according to the Friend List documentation the members connection is An array of objects containing friend id and name fields. - those are the only two fields in
the structure - you'll need to fetch any other data you need about those IDs in another call
(Though most apps would probably already have the result of /me/friends cached so this should be pretty fast)
You wouldn't be able to pull the gender in one go as Igy said, so a way to do it in FQL would be
SELECT uid, sex FROM user WHERE uid IN (SELECT uid, flid FROM friendlist_member WHERE flid = <friendlist_id>)

Categories