Google-api-dotnet-client: Exception using People API

Created on 13 Nov 2017  路  9Comments  路  Source: googleapis/google-api-dotnet-client

The dotnet client does not have any documentation of People API. I am trying to use People API by imitating the documentation of Java samples given here: https://developers.google.com/people/quickstart/java. Here's what I've tried:

```C#
public void Connections()
{
// Request 10 connections.

        var request = service.People.Connections
            .List("people/me");

        request.PageSize = 10;
        //request.Fields = "names,emailAddresses";
        request.Fields = "names";

        var response = request.Execute();

        // Print display name of connections if available.
        var connections = response.Connections;

        foreach (var connection in connections)
        {
            var names = connection.Names;
            foreach (var name in names)
            {
                Console.WriteLine($"{name.DisplayName}");
            }
        }
    }

```

Unfortunately I'm seeing the following exception:

Google.GoogleApiException
HResult=0x80131500
Message=Google.Apis.Requests.RequestError
Request contains an invalid argument. [400]
Errors [
Message[Invalid Parameter] Location[fields - parameter] Reason[invalidParameter] Domain[global]
]

Source=Google.Apis

Most helpful comment

Now it works. It looks like there are two different nuget packages from Google for People API. To make matter worse the older one comes up top when searched in Visual Studio.

All 9 comments

I suspect the problem is your use of Fields - have you tried using PersonFields instead? That mirrors what the Java example does, and matches the reference documentation

There's no PersonFields in the dot net version, only Fields.

It should be there - it's in the source code:

/// <summary>**Required.** A field mask to restrict which fields on each person are returned. Valid
/// values are:
///
/// * addresses * ageRanges * biographies * birthdays * braggingRights * coverPhotos * emailAddresses *
/// events * genders * imClients * locales * memberships * metadata * names * nicknames * occupations *
/// organizations * phoneNumbers * photos * relations * relationshipInterests * relationshipStatuses *
/// residences * skills * taglines * urls</summary>
[Google.Apis.Util.RequestParameterAttribute("personFields", Google.Apis.Util.RequestParameterType.Query)]
public virtual object PersonFields { get; set; }

Where were you trying to set it?

(It's annoying that it's of type object, admittedly... not sure why that is.)

This is the error message I get if I try to use PersonFields:

'PeopleResource.ConnectionsResource.ListRequest' does not contain a definition for 'PersonFields' and no extension method 'PersonFields' accepting a first argument of type 'PeopleResource.ConnectionsResource.ListRequest' could be found (are you missing a using directive or an assembly reference?)

This is what I see the source code from metadata of the nuget package:

```C#
//
// Summary:
// Provides a list of the authenticated user's contacts merged with any linked profiles.
public class ListRequest : PeopleBaseServiceRequest
{
//
// Summary:
// Constructs a new List request.
public ListRequest(IClientService service, string resourceName);

            //
            // Summary:
            //     The resource name to return connections for. Only `people/me` is valid.
            [RequestParameter("resourceName", RequestParameterType.Path)]
            public virtual string ResourceName { get; }
            //
            // Summary:
            //     The order in which the connections should be sorted. Defaults to `LAST_MODIFIED_ASCENDING`.
            [RequestParameter("sortOrder", RequestParameterType.Query)]
            public virtual SortOrderEnum? SortOrder { get; set; }
            //
            // Summary:
            //     Whether the response should include a sync token, which can be used to get all
            //     changes since the last request.
            [RequestParameter("requestSyncToken", RequestParameterType.Query)]
            public virtual bool? RequestSyncToken { get; set; }
            //
            // Summary:
            //     The token of the page to be returned.
            [RequestParameter("pageToken", RequestParameterType.Query)]
            public virtual string PageToken { get; set; }
            //
            // Summary:
            //     The number of connections to include in the response. Valid values are between
            //     1 and 500, inclusive. Defaults to 100.
            [RequestParameter("pageSize", RequestParameterType.Query)]
            public virtual int? PageSize { get; set; }
            //
            // Summary:
            //     Comma-separated list of fields to be included in the response. Omitting this
            //     field will include all fields except for connections.list requests, which have
            //     a default mask that includes common fields like metadata, name, photo, and profile
            //     url. Each path should start with `person.`: for example, `person.names` or `person.photos`.
            [RequestParameter("requestMask.includeField", RequestParameterType.Query)]
            public virtual object RequestMaskIncludeField { get; set; }
            //
            // Summary:
            //     A sync token, returned by a previous call to `people.connections.list`. Only
            //     resources changed since the sync token was created will be returned.
            [RequestParameter("syncToken", RequestParameterType.Query)]
            public virtual string SyncToken { get; set; }
            //
            // Summary:
            //     Gets the method name.
            public override string MethodName { get; }
            //
            // Summary:
            //     Gets the HTTP method.
            public override string HttpMethod { get; }
            //
            // Summary:
            //     Gets the REST path.
            public override string RestPath { get; }

            //
            // Summary:
            //     Initializes List parameter list.
            protected override void InitParameters();

            //
            // Summary:
            //     The order in which the connections should be sorted. Defaults to `LAST_MODIFIED_ASCENDING`.
            public enum SortOrderEnum
            {
                LASTMODIFIEDASCENDING = 0,
                FIRSTNAMEASCENDING = 1,
                LASTNAMEASCENDING = 2
            }
        }

```

The nuget package might not have been updated in a while. The latest version has been published at Tuesday, April 11, 2017 (4/11/2017).

Ah - I think I see the problem. Try using Google.Apis.PeopleService.v1 instead of Google.Apis.People.v1.

Now it works. It looks like there are two different nuget packages from Google for People API. To make matter worse the older one comes up top when searched in Visual Studio.

Yes, I suspect the name changed in the discovery doc in April. The first version of the PeopleService library was in April 2017. Unfortunately there's not much we can do on that front :(

Can you unlist the Google.Apis.People.v1 package? https://www.nuget.org/packages/Google.Apis.People.v1/

Was this page helpful?
0 / 5 - 0 ratings