Migrating from google calendar api v2 to v3 - Client Authorization - oauth-2.0

I coded a desktop calendar application a while ago, based on an existing database for an older calendar.
A bit later I added functionality to interact with google calenders using the v2 api, that is deprecated for a while now. Functionality might brake in november: Deprecation Policy ..so I thought it's about time to update to the v3 api.
What my calendar application does related to google calendar:
Writing/Reading in a shared google calendar
Writing/Reading in own (multiple) private google calendars
Syncing private/shared google calendars into an own database.
In v2 it was pretty easy to login to any calendar having the credentials with the GoogleDataApi
CalendarService calService = new CalendarService("MyCalendar");
calService.setUserCredentials(account, password);
and then reading, writing, update events.
In the v3 api theres no clientlogin anymore, how would I proceed with oauth2 to achieve the same functionality? How would I let a user login from my desktop application to his google calendars, so he is able to sync/view/edit/add google events?

Updating is a good idea! For v3 you should take a look at Oauth2 for desktop app (you will need to get and store Oauth2 access token and a refresh token for your users to not need the user to re-enter their credentials). The calendar documentation for this: https://developers.google.com/google-apps/calendar/auth
The generic Oauth2 documentation: https://developers.google.com/accounts/docs/OAuth2InstalledApp
Some more documentation from drive: https://developers.google.com/drive/web/about-auth
And the most useful of all, the playground to try stuff out: https://developers.google.com/oauthplayground/

Related

Use google calendar with Symfony

I want to access to the calendar to read/create event from the user if he agrees.
I've followed the guide https://developers.google.com/google-apps/calendar/v3/sync
I've actived the api with my google account. Then use the OAuth 2.0 to get a code and the token.
When I follow the test, I use another account to simulate a random user.
Arrived at the lecture of the agenda, I get this error:
Error calling GET https://www.googleapis.com/calendar/v3/calendars/primary/events?maxResults=10&orderBy=startTime&singleEvents=true&timeMin=2016-06-14T11%3A28%3A25%2B02%3A00: (403) Access Not Configured. Calendar API has not been used in project 1056... before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar/overview?project=1056... then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
It seems legit but I don't want the user to active the api on his side...
What am I missing?
Go to Google Developers console and enable the Google Calendar API. You need to tell Google which APIs your application will be accessing.

Access Google Calendar in IOS using Service Account

I need to access a NON-public Google calendar WITHOUT requiring the user to log in or even have a Google account.
I created an Android app that accesses a Google calendar using a service account:
GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(httpTransport)
.setJsonFactory(jsonFactory)
.setServiceAccountId(serviceAccountID)
.setServiceAccountScopes(scopes)
.setServiceAccountPrivateKeyFromP12File(licenseFile)
.build();
com.google.api.services.calendar.Calendar.Builder builder = new com.google.api.services.calendar.Calendar.Builder(httpTransport, jsonFactory, credential);
builder.setApplicationName(appName);
com.google.api.services.calendar.Calendar client = builder.build();
com.google.api.services.calendar.Calendar.Events.List list = client.events().list(calendarID);
list.setMaxAttendees(maxAttendees);
list.setTimeZone(timeZone);
list.setTimeMin(startTime);
list.setTimeMax(endTime);
list.setOrderBy(orderBy);
list.setShowDeleted(showDeleted);
list.setSingleEvents(true);
Events events = list.execute();
This included:
Creating a project in the Google App console
Creating a Service Account
Giving the Service Account access rights to the Google calendar
It works GREAT!
I need to do the same thing in IOS. I have read every question/answer I can find on this topic and have found VERY different answers. Many say that Google hasn't allowed this in the IOS SDK because service accounts are intended to be used by server-based applications. I don't agree since the functionality I need is available in Android. So, now what?
The use case is this:
My IOS app needs to access a Google calendar. That part is not too tough if you are okay with using OAuth. My problems with this approach are:
Requires to user to have a Google account. Many of my users are Apple-Only. I can't require them to get a Google account just to use my app.
I can't make the calendar public. So, I would need to give access to every new user. I guess I could do that with a web-based application but this doesn't fix the problem (refer to previous problem - no Google account).
I really need to be able to query the events in the NON-public Google Calendar WITHOUT the user needing a Google account. The solution IS using a "Service Account" (I think).
I read one question/answer that said this is possible but the solution was never posted. (How to list Google Calendar Events without User Authentication)
HELP!!!!
The official documentation suggests that if you want to handle Calendar API (for example), you'll have to have a Google Apps for Work (source).
If you have a Google Apps domain—if you use Google Apps for Work, for example—an administrator of the Google Apps domain can authorize an application to access user data on behalf of users in the Google Apps domain. For example, an application that uses the Google Calendar API to add events to the calendars of all users in a Google Apps domain would use a service account to access the Google Calendar API on behalf of users.
Once the prerequisite is met, you can try to just call the REST URLs of Calendar API based on your implementation (since there seems to be no iOS support or samples available in the documentation).

How to list Google Calendar Events without User Authentication

On November 17, 2014 Google deprecated v1 and v2 of its Google Calendar API using the Zend Framework.
It seems the only way to list publicly shared events on a publicly shared Google Calendar is through the new Google Client Library API from GitHub using OAuth 2.0
This means visitors to a public website that used to display public events now have to authenticate and login.
Is that true? Is there no other way to continue to show public Google Calendar events?
What you need to do is use a Service account for this. You will then be able add the service accounts email address as a user to the calendar for your website. The Service account will then be able to access this calendar including the events
You can still retrieve all public data without Oauth2, you just need to register in a developer console and create an API key. Then you can do:
GET https://www.googleapis.com/calendar/v3/calendars/<CALENDAR_EMAIL>/events?key={YOUR_API_KEY}

How do I authenticate Google Calendar API v3 without user interaction?

I'm using Google and external calendar sync (console application). I've tried several ways to connect to my calendar in Delphi. In the latest version of the Google API, you can choose two options:
API Key (public calendar)
OAuth2.0 (private calendar)
The calendar is not public. I looked at a couple of examples, but everywhere the need for user interaction. I want to identify myself with no user interaction. How can I do that?
I don't know about using it in Delphi but there is a client API library for java, python... I've already used the java one and it's clearly explained how to use it in the documentation.
Google Calendar API 3 Doc page:
https://developers.google.com/google-apps/calendar/
However, the service asks you to be authentified to used it (which is your problem if I understand it well, you don't want the user to have to authenticate). So I suggest you to have a look on OAuth2.0. https://developers.google.com/google-apps/calendar/auth
Here are some simple of using google-api-java-client for exemple : https://code.google.com/p/google-api-java-client/wiki/OAuth2
And you should look more precisely at Google OAuth service account possibilities.
Service Account with OAuth2.0. (See here : https://developers.google.com/accounts/docs/OAuth2#serviceaccount).
It will provide a service account for your application, from which you will be able to handle calendars for your app.
And here you will find a sample showing how to do it with Java. (https://code.google.com/p/google-api-java-client/wiki/OAuth2#Service_Accounts). But maybe this is the public API Key you are talking about... Not sure I remember properly.
I hope this will help you to figure out how to do it.

Should I stop using google API V2?

I have an application for my client that uploads videos on youtube on behalf of my client.
What my client do is provide his user name and password in my app and then app uploads videos using Youtube DATA API V2(Username/password credentials).
But since username/password authentication mechanism is not available in V3, I have to change the user involvement that is required in the new Authorization mechanism. But my client is does not agree.
The question is, what if I continue to use API V2 and not switch to V3. Is there any chance that Google will stop V2 and I have to move to V3?
Is there any way I keep authenticating using credentials and not switch to OAuth 2.0?
You asked: Is there any chance that google will stop V2 and I have to move to V3?
Short answer: You need to switch to YouTube's v3 API.
From Google:
The YouTube Data API (v2) has been officially deprecated as of March 4, 2014. Please refer to our deprecation policy for more information. Please use the YouTube Data API (v3) for new integrations and migrate applications still using the v2 API to the v3 API as well.
If you haven’t yet migrated from the previous API version (v2), we wanted to remind you it will be unsupported as of April 20, 2015, and shut down soon thereafter. To make it fast and easy for you to migrate, check out the new Migration Guide. It’ll help you identify the v3 API methods and parameters that correspond to the functionality that you've been using in the v2 API. It also points out new features that the v3 API supports.
Source
Your second question: Is there any way I keep authenticating using credentials and not switch to OAuth 2.0? I do not know the answer to. Maybe ask as a separate question?

Resources