5

I'm using Google APIs to get the user's calendar events and contacts.

While fetching the contacts, I get the response in the following manner:-

[
    {
        'phones': [],
        'image_path': '',
        'id': 'ID',
        'emails': ['email1'],
        'name': ABC
    },
    {
        'phones': [],
        'image_path': '',
        'id': 'ID',
        'emails': ['email2'],
        'name': DEF
    }
]

While fetching the events, I get the follwoing response:-

[
    {
        'attendees': [{
            'organizer': True,
            'displayName': 'ABC',
            'id': 'Google+ Id',
            'responseStatus': 'accepted'
        }, {
            'self': True,
            'displayName': 'DEF',
            'id': 'Google+ id',
            'responseStatus': 'accepted'
        }],
        'organizer': {
            'displayName': 'ABC',
            'id': 'Google+ id'
        },
        'creator': {
            'displayName': 'ABC',
            'id': 'Google+ id'
        },
    },
    {
        'organizer': {
            'self': True,
            'displayName': 'DEF',
            'email': 'email2'
        },
        'creator': {
            'self': True,
            'displayName': 'DEF',
            'email': 'email2'
        },
    }
] 

As you can see that while fetching events, (in attendees, organizers, creators) I get Google+ id in some cases and email_ids in other cases. This does not maintain a uniformity in my code.

Since I've fetched the user contacts as well, and I search the contacts via their email_ids. If I don't get an email_id in attendees, organizers, or creators, I won't be able to reference the contact object.

How can I make sure that I get only the email_ids in attendees, not the Google+ id.

Mogsdad
  • 44,709
  • 21
  • 151
  • 275
Praful Bagai
  • 16,684
  • 50
  • 136
  • 267
  • I am able to get just email addresses just fine with the [Events.get](https://developers.google.com/google-apps/calendar/v3/reference/events/get#try-it) method. Since, I'm not sure exactly how the request looks. If you set the fields param with just the displayName and email. You should get be able to get exactly what you need. Hope that helps. – Andres Dec 14 '15 at 22:37
  • Thanks for the response. Whenever I try to add any `fields` it says, `Invalid field selection creator`. It returns the same error for any type of field. – Praful Bagai Dec 16 '15 at 07:44
  • The only user whose id field is missing is the one with the `self` field labelled as `True`...does that help? – slushy Dec 19 '15 at 08:37
  • No, because I'm not getting email ids in some event's attendees – Praful Bagai Dec 19 '15 at 09:00

1 Answers1

1

According to Google Calendar API docs

Optional query parameters

alwaysIncludeEmail

boolean Whether to always include a value in the email field for the organizer, creator and attendees, even if no real email is available (i.e. a generated, non-working value will be provided). The use of this option is discouraged and should only be used by clients which cannot handle the absence of an email address value in the mentioned places. Optional. The default is False.

Anyway it is not encouraged to use it , because sometimes no real email is available.

Work around:

You can use G+ API to fetch user Email through providing his/her email.

email
This scope requests that your app be given access to:

the user's Google account email address. You access the email address by calling people.get, which returns the emails array (or by calling people.getOpenIdConnect, which returns the email property in OIDC-compliant format). the name of the Google Apps domain, if any, that the user belongs to. The domain name is returned as the domain property from

people.get (or hd property from getOpenIdConnect)

This email scope is equivalent to and replaces the https://www.googleapis.com/auth/userinfo.email scope.

ProllyGeek
  • 15,517
  • 9
  • 53
  • 72