Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get email_ids only (not G+ id) from Events API

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.

like image 793
PythonEnthusiast Avatar asked Nov 09 '22 23:11

PythonEnthusiast


1 Answers

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.

like image 73
ProllyGeek Avatar answered Nov 28 '22 03:11

ProllyGeek