MarcelRobitaille / nextcloud_google_synchronization

🇬 Google integration into Nextcloud
GNU Affero General Public License v3.0
18 stars 1 forks source link

Error in background sync job #3

Closed Foxite closed 5 days ago

Foxite commented 1 year ago

After clicking "sync calendars", these errors are logged every 5 minutes:

[PHP] Error: Error: Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#193 at <> 0. /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php line 193 OC\Log\ErrorHandler::onError(2, "Undefined prope ... e", "/var/www/html/c ... p", 193) 1. /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php line 26 OCA\Google\Service\GoogleCalendarAPIService->safeImportCalendar("[REDACTED-token?]", "[REDACTED-nextcloud user id]", "[REDACTED-google email]", "[REDACTED-google email]") 2. /var/www/html/lib/public/BackgroundJob/Job.php line 78 OCA\Google\BackgroundJob\ImportCalendarJob->run([[REDACTED-token? same from before]]) 3. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 103 OCP\BackgroundJob\Job->start(OC\BackgroundJob\JobList {}) 4. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 93 OCP\BackgroundJob\TimedJob->start(OC\BackgroundJob\JobList {}) 5. /var/www/html/cron.php line 152 OCP\BackgroundJob\TimedJob->execute(OC\BackgroundJob\JobList {}, OC\Log {}) at 2023-02-01T10:25:01+00:00 [google_synchronization] Warning: Google API ServerException|ClientException error : Client error: `GET https://www.googleapis.com/calendar/v3/colors` resulted in a `403 Forbidden` response: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { (truncated...) status code: 403 body: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The request is missing a valid API key.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } } at 2023-02-01T10:30:01+00:00 [google_synchronization] Warning: Google API ServerException|ClientException error : Client error: `GET https://www.googleapis.com/calendar/v3/calendars/[REDACTED-nextcloud user id]/events?maxResults=2500` resulted in a `403 Forbidden` response: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { (truncated...) status code: 403 body: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The request is missing a valid API key.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } } at 2023-02-01T10:30:01+00:00 [PHP] Error: Error: Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#207 at <> 0. /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php line 207 OC\Log\ErrorHandler::onError(2, "Undefined prope ... e", "/var/www/html/c ... p", 207) 1. /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php line 26 OCA\Google\Service\GoogleCalendarAPIService->safeImportCalendar("[REDACTED-token? same from before]", "[REDACTED-nextcloud user id]", "[REDACTED-google email]", "[REDACTED-google email]") 2. /var/www/html/lib/public/BackgroundJob/Job.php line 78 OCA\Google\BackgroundJob\ImportCalendarJob->run([[REDACTED-token? same from before]]) 3. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 103 OCP\BackgroundJob\Job->start(OC\BackgroundJob\JobList {}) 4. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 93 OCP\BackgroundJob\TimedJob->start(OC\BackgroundJob\JobList {}) 5. /var/www/html/cron.php line 152 OCP\BackgroundJob\TimedJob->execute(OC\BackgroundJob\JobList {}, OC\Log {}) at 2023-02-01T10:30:01+00:00 [PHP] Error: Error: Undefined array key "nbAdded" at /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php#28 at <> 0. /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php line 28 OC\Log\ErrorHandler::onError(2, "Undefined array key \"nbAdded\"", "/var/www/html/c ... p", 28) 1. /var/www/html/lib/public/BackgroundJob/Job.php line 78 OCA\Google\BackgroundJob\ImportCalendarJob->run([[REDACTED-token? same from before]]) 2. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 103 OCP\BackgroundJob\Job->start(OC\BackgroundJob\JobList {}) 3. /var/www/html/lib/public/BackgroundJob/TimedJob.php line 93 OCP\BackgroundJob\TimedJob->start(OC\BackgroundJob\JobList {}) 4. /var/www/html/cron.php line 152 OCP\BackgroundJob\TimedJob->execute(OC\BackgroundJob\JobList {}, OC\Log {}) at 2023-02-01T10:30:01+00:00

Notably, these errors continue to occur after I've disconnected my google account.

Also notably, the third error indicates that a request was made to google that included my nextcloud user ID - this is a unique string that google has no business knowing, so it's probably an error that this gets sent.

Probably also of note is that I did not add the google drive, people and photo's APIs to the app in the google console, because I only want to sync calendar data and I don't think it needs those APIs for that. I also did not authorize these scopes when connecting my account.

Finally, this error only seems to occur on the background job schedule, and it doesn't happen when I manually click the import calendar button - in fact, that works properly (except that events regarding office hours don't show up, which I will make a feature request for).

Foxite commented 1 year ago

It might also be worth mentioning that the first time I tried to use this, I got this error, but I have since fixed it. Perhaps this error prevented the api key from being saved.

[google_synchronization] Warning: Google API ServerException|ClientException error : Client error: `GET https://www.googleapis.com/calendar/v3/users/me/calendarList` resulted in a `403 Forbidden` response: { "error": { "code": 403, "message": "Google Calendar API has not been used in project [REDACTED-project id] before or (truncated...) status code: 403 body: { "error": { "code": 403, "message": "Google Calendar API has not been used in project [REDACTED-project id] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar-json.googleapis.com/overview?project=[REDACTED-project id] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", "errors": [ { "message": "Google Calendar API has not been used in project [REDACTED-project id] before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/calendar-json.googleapis.com/overview?project=[REDACTED-project id] then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.", "domain": "usageLimits", "reason": "accessNotConfigured", "extendedHelp": "https://console.developers.google.com" } ], "status": "PERMISSION_DENIED", "details": [ { "@type": "type.googleapis.com/google.rpc.Help", "links": [ { "description": "Google developers console API activation", "url": "https://console.developers.google.com/apis/api/calendar-json.googleapis.com/overview?project=[REDACTED-project id]" } ] }, { "@type": "type.googleapis.com/google.rpc.ErrorInfo", "reason": "SERVICE_DISABLED", "domain": "googleapis.com", "metadata": { "service": "calendar-json.googleapis.com", "consumer": "projects/[REDACTED-project id]" } } ] } } GET /apps/google_synchronization/calendars from [REDACTED-ip address] by [REDACTED-nextcloud user id] at 2023-02-01T10:14:59+00:00
dmitry-entin commented 1 year ago

Hello! I also have an error about missed API key in result of background sync. One time import works like a charm...

Error text

Google API ServerException|ClientException error : Client error: `GET https://www.googleapis.com/calendar/v3/calendars/wmd/events?maxResults=2500` resulted in a `403 Forbidden` response: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { (truncated...) status code: 403 body: { "error": { "code": 403, "message": "The request is missing a valid API key.", "errors": [ { "message": "The request is missing a valid API key.", "domain": "global", "reason": "forbidden" } ], "status": "PERMISSION_DENIED" } }

And there are two additional errors in the Log, PHP related

Additional errors

Error: Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#207 Error: Undefined array key "nbAdded" at /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php#28

I use AIO docker image, default configuration. First, I'd enabled "Google Integration" app and made an initial import and then I've disabled it and enabled "Google Syncronization" app, reconfigured OAuth2 in Google API config (redirect URI).

What should I fix to get background sync work correctly?

RyanVerhey commented 1 year ago

I am having the same issues, with the same error messages

dmitry-entin commented 1 year ago

Error: Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#207

This one could be solved just by commenting out the line 207 in the GoogleCalendarAPIService.php file, couse it's just a debug message.

Error: Undefined array key "nbAdded" at /var/www/html/custom_apps/google_synchronization/lib/BackgroundJob/ImportCalendarJob.php#28

This one also could be solved just by commenting out the line 28 in the ImportCalendarJob.php file, couse it's echoing the informational message.

dmitry-entin commented 1 year ago

The main problem (a lack of accessToken) could be connected to this error message Error: Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#207

By the documentation, $this->appName is used to set/get accessToken to/from User config values: https://docs.nextcloud.com/server/latest/developer_manual/basics/storage/configuration.html#user-values

But in the ConfigController.php file "Application::APP_ID" is used instead of appName... $this->config->setUserValue($this->userId, Application::APP_ID, 'token', $accessToken);

Oh mighty Creator, come and save us! :)

BeatrizFernandezLarrubia commented 1 year ago

Hello, I am having the exact same error. I tried some of the solutions in this post, but what I have tried does not seem to work. I will continue trying the solutions given there and update if something happens!

dmitry-entin commented 1 year ago

Hi! I've updated my NextCloud to 25.0.6, now I have this errors in logs:

Google OAuth error : Client error: POST https://oauth2.googleapis.com/token resulted in a 400 Bad Request response: { "error": "invalid_grant", "error_description": "Bad Request" }

Google API error, impossible to refresh the token. Response: {"error":"Client error: POST https:\/\/oauth2.googleapis.com\/token resulted in a 400 Bad Request response:\n{\n \"error\": \"invalid_grant\",\n \"error_description\": \"Bad Request\"\n}\n"}

Google API ServerException|ClientException error : Client error: GET https://www.googleapis.com/oauth2/v1/userinfo?alt=json resulted in a 401 Unauthorized response: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 (truncated...) status code: 401 body: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

MarcelRobitaille commented 4 months ago

Could you please try the latest release and let me know if you are still experiencing this issue.

dmitry-entin commented 3 months ago

Hello! I've updated to the latest release (manually, there is no update through Apps menu in NC). Going to monitor how it works now.

But I have these lines in Logging:

Error | PHP | Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#177 Error | PHP | Undefined property: OCA\Google\Service\GoogleCalendarAPIService::$appName at /var/www/html/custom_apps/google_synchronization/lib/Service/GoogleCalendarAPIService.php#191

Warning | google_synchronization | Error when creating calendar event "" An exception occurred while executing a query: SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xd0 CONTEXT: unnamed portal parameter $6 Warning | google_synchronization | Error when creating calendar event "" An exception occurred while executing a query: SQLSTATE[22021]: Character not in repertoire: 7 ERROR: invalid byte sequence for encoding "UTF8": 0xd1 CONTEXT: unnamed portal parameter $6

MarcelRobitaille commented 3 months ago

@dmitry-entin really? It should be in the app store: https://apps.nextcloud.com/apps/google_synchronization

This looks like #15. Could you please update to 2.1.0-2-nightly and see if it goes away?

dmitry-entin commented 3 months ago

Hm, I tried to update via NextCloud admin interface (Apps list) and it didn't show new version :( Nightly version should be installed manually? I'll try but later this week...

MarcelRobitaille commented 5 days ago

I will close this now for inactivity. Please feel free to reopen it if it's still a problem.

Also, I solved the problem with new versions not showing up in the NC UI.