Building google calendar api app for my garmin watch, but google doens't have support for MonkeyC language

84 views Asked by At

I would like to go thru upcoming events from my google calendar on my garmin watch. Here is the guide from google how to use their api with different languages, python for instance https://developers.google.com/calendar/api/quickstart/python?hl=pl How to implement this in Monkey C? Here is what I found in garmin documentation https://developer.garmin.com/connect-iq/api-docs/Toybox/Communications.html

I managed create new api for my account in google canledar. Have all credentials in json file: client_id, project_id, auth_uri, token_uri, auth_provider_x509_cert_url. Here is the code from garmin doc, that I completed with credentials from google project. I put it in View.mc file. I get the error message: "extraneous input 'Communications' expecting {, 'class', 'module', 'using', 'import', 'alias'"

`using Toybox.Communications;
 using Toybox.System;

const CLIENT_ID = *******
const OAUTH_CODE = "https://accounts.google.com/o/oauth2/auth";
const OAUTH_ERROR = "access_denied";

// the OAuth service can now be used with a makeWebRequest() call
// register a callback to capture results from OAuth requests
Communications.registerForOAuthMessages(method(:onOAuthMessage));



// wrap the OAuth request in a function
function getOAuthToken() {
   status = "Look at OAuth screen\n";
   Ui.requestUpdate();

   // set the makeOAuthRequest parameters
   var params = {
       "scope" => Comm.encodeURL("https://www.googleapis.com/auth/calendar.readonly"),
       "redirect_uri" =>  "https://oauth2.googleapis.com/token",
       "response_type" => "code",
       "client_id" => $.CLIENT_ID
   };

   // makeOAuthRequest triggers login prompt on mobile device.
   // "responseCode" and "responseError" are the parameters passed
   // to the resultUrl. Check the oauth provider's documentation
   // to determine the correct strings to use.
   Comm.makeOAuthRequest(
       "https://accounts.google.com/o/oauth2/auth",
       params,
       "https://oauth2.googleapis.com/token",
       Comm.OAUTH_RESULT_TYPE_URL,
       {"responseCode" => $.OAUTH_CODE, "responseError" => $.OAUTH_ERROR}
   );
}

// implement the OAuth callback method
function onOAuthMessage(message) {
    if (message.data != null) {
        var code = message.data[$.OAUTH_CODE];
        var error = message.data[$.OAUTH_ERROR];
    } else {
        // return an error
    }
}

0

There are 0 answers