1

I´m developing a simple application to retrieve all the events of a calendar. The app only has 1 textbox (to fill with the account), 1 datagridview (to fill with all events data) and 1 button (to execute).

It works fine when I write my google account (which I used in Google API console) in the textbox but when I try with other accounts (even when they are signed in the browser) it shows me a 404 error.

How can I achieve it for multiples accounts?

This is my code to get all my events:

Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Services
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.EventsResource
Imports System.Threading
Public Class Form1
Dim scopes As IList(Of String) = New List(Of String)
Dim service As CalendarService
Dim initializer = New BaseClientService.Initializer
Dim Secrets = New ClientSecrets()

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        scopes.Add(CalendarService.Scope.Calendar)
        Secrets.ClientId = "CLIENT ID"
        Secrets.ClientSecret = "CLIENT SECRET"
        Dim credential = GoogleWebAuthorizationBroker.AuthorizeAsync(Secrets, scopes, "DEVELOPER EMAIL", CancellationToken.None).Result()
        Dim initializer = New BaseClientService.Initializer
        initializer.HttpClientInitializer = credential
        initializer.ApplicationName = "APPLICATION NAME"
        service = New CalendarService(initializer)
        Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items
        Dim requeust As ListRequest = service.Events.List(TextBox1.Text)
        Me.DataGridView1.DataSource = requeust.Execute.Items
End Sub
End Class

What can I do?

Thanks.

Alan Alvarez
  • 646
  • 2
  • 11
  • 32

2 Answers2

2

404: Not Found means that the specified resource was not found. This can happen in several cases. Here are some examples:

  • when the requested resource has never existed.
  • when accessing a calendar that the user can not access.

Official Google Documentation suggested to implement exponential backoff exponential backoff is a standard error handling strategy for network applications in which the client periodically retries a failed request over an increasing amount of time. If a high volume of requests or heavy network traffic causes the server to return errors, exponential backoff may be a good strategy for handling those errors. Conversely, it is not a relevant strategy for dealing with errors unrelated to rate-limiting, network volume or response times, such as invalid authorization credentials or file not found errors.

Used properly, exponential backoff increases the efficiency of bandwidth usage, reduces the number of requests required to get a successful response, and maximizes the throughput of requests in concurrent environments.

Regarding access to multiple account, it's the Oauth tokens that decide which account will be accessed, it's not the client secret or the project you are using. You can use the same project in the console for retrieving data from both the accounts. However, you will need to request a separate OAuth token for each of them and then use it for accessing the data. Please check OAuth 2.0 documentation: https://developers.google.com/identity/protocols/OAuth2

Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
0

As I know in all of the google API must create an API token first, although your account has been created a new token, but for the others was not, so it may be the reason that you can't successful use the API in other account, same as the google map API.

Please check with how to create a guest account API for all of the user.
Not sure is that can help for your question, but it was close with what you want:
How do I connect to the Google Calendar API without the oAuth authentication?

Best regards,
KT

Community
  • 1
  • 1
koi tsang
  • 13
  • 4