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

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>)

Related

How do I get the parent folder using the Google Drive API?

I'm trying to write a method that gets the parent folder of the folder whose Id is passed in. I have tried many different variations, most of which come from accepted answers here, but every one causes an exception.
For example, the following code...
public async Task<DriveFile> GetParentFolder(string folderId) {
FilesResource.ListRequest request = _service.Files.List();
request.Q = $"parents contains '{folderId}'";
request.Fields = "*";
FileList files = await request.ExecuteAsync();
return files.Files[0];
}
...throws the following exception...
Error: The service drive has thrown an exception: Google.GoogleApiException: Google.Apis.Requests.RequestError
Invalid Value [400]
Errors [
Message[Invalid Value] Location[q - parameter] Reason[invalid] Domain[global]
]
I have tried many values for the Q and Fields properties, but all result in the same exception.
I have other code working with the API, so it's not the basic service that's a problem, and I've used the API to get the Ids of some folders, so I know I'm passing in a valid value.
One of the problems is that v2 of the API had a Parents list, which looks like it does what I want, but this seems to be missing in v3.
Anyone able to help me? Thanks
Your going about it the wrong way you dont need to use file.list you already have the file id just use file.get.
Lets say i have the folder id here.
{
"kind": "drive#file",
"id": "1bzDkXlcND_yycIcbqwr1YYZ98-Yv7SG7",
"name": "Current Badges (2019-21)",
"mimeType": "application/vnd.google-apps.folder"
},
As you can see in this example i have the id and the mime type is a folder.
All i need to do is do a file.get
var request = _service.Files.Get("1bzDkXlcND_yycIcbqwr1YYZ98-Yv7SG7");
request.Fields = "parents";
var response = request.Execute();
The response will contain a filed called parents which is the parent of the folder.
As you can see if you already know the file id or in this case the folder id. Then you really just need to use file.get to get all the information about that id.
There's really no reason to use file.list.

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)

OData of Outlook Event List cannot order by "Id"

I tried to get a list of events from Microsoft Graph following this documentation.
I would like to get the list with order by lastModifiedDateTime and then id.
Here is the sample query:
var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime, id", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));
However, when I executed it, it results an error:
{
"error": {
"code": "ErrorInvalidProperty",
"message": "The property 'Id' does not support filtering.",
"innerError": {
"request-id": "bb56a0d0-46f3-4b7c-80bd-043a0b3fd8b5",
"date": "2018-09-17T15:23:40"
}
}
}
In fact, I didn't set the Id within $filter, but instead, I set it as $orderby.
When I tried to exclude the Id from $orderby, it works. Here is the working query:
var getResource = string.Format("/me/calendar/events/?$filter=lastModifiedDateTime ge {0}&$orderBy=lastModifiedDateTime", XmlConvert.ToString(updatedMin, XmlDateTimeSerializationMode.Utc));
Anyone has an idea on how to order the list based on Id as well?
You cannot order by id, nor would it make any sense to do so. The id is a hashed combination of several properties (subject, path, etc.). As such, their value is neither orderable or human-readable.
This, for example, is an actual id value:
AAMkAGVmMDEzMTM4LTZmYWUtNDdkNC1hMDZiLTU1OGY5OTZhYmY4OABGAAAAAAAiQ8W967B7TKBjgx9rVEURBwAiIsqMbYjsT5e-T7KzowPTAAAAAAENAAAiIsqMbYjsT5e-T7KzowPTAACNM9xPAAA=
Also, I strongly recommend using the Microsoft Graph .NET Client rather than rolling your own. It will help reduce the learning curve and give you more readable code:
await graphClient.Me
.Calendar
.Events
.Request()
.Filter("lastModifiedDateTime ge {dateTime}")
.OrderBy("lastModifiedDateTime")
.GetAsync();

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.

Facebook API - getting friend list with detail info again

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.

Categories