Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Google Calendar API

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Google Calendar API

    Has anyone had any success of using Google Calendar API with A5 ?

    I have no real idea where to start, so was hoping for some guidance if anyone has done so.

    thanks,
    chris

    #2
    Re: Google Calendar API

    I have alot of experience with it. In fact, I've been writing a XBasic class for it. I would HIGHLY recommend a few links from Google. https://developers.google.com/google.../v3/reference/ as well as https://developers.google.com/accounts/docs/OAuth2

    Start with the OAuth2 article if your app is going to need authentication. Ask any questions you want and I've more than likely dealt with it. I'm not quite ready to share my XBasic class in total (not quite 100% complete), but I will definitely share snippets to help you out.

    As for me, My app uses a Five different google accounts (for 5 different regions) and has between 4-7 individual calendars per account. A person can set an appointment by clicking a box and typing in a little bit of information. At that point, it saves the event to the correct calendar. (which is then available for syncing on smartphones). My code takes care of auth tokens (which must be refreshed every 60 minutes of use using a refresh token). I wrote this app before Alpha fixed their JSON implementation, so I use a 'man in the middle' PHP script to help with the JSON, but I've been meaning to convert it pure xbasic. I also use a jQuery calendar call FullCalendar (http://arshaw.com/fullcalendar/) which, when combined with one of my scripts, can also display events from Google calendar on my site.

    Ask away :)

    Comment


      #3
      Re: Google Calendar API

      Thank you for the reply! That is exactly what I'm trying to accomplish.. use a jQuery Calendar and have it sync to Google so it can sync with smartphones.

      I think I can figure out the JSON stuff, but I'm just really stuck on how to implement the security oAuth2. Can you start by providing code to handle that by chance? I know very little of JSON but have been spending a lot of time reading about it today.

      Comment


        #4
        Re: Google Calendar API

        OK, a quick how to on oauth2. (Reference: https://developers.google.com/accounts/docs/OAuth2 )
        1. First off, you must register your application with Google APIs Console.
          So create a project and go to Services, turning on Google Calendar API v3 (Free up to 25,000 Requests per day)
          Under API Access you will need to create a new Client ID for web apps.
          This will give you information that you will need later on.
          Reference: https://code.google.com/apis/console/
        2. Next, we need to create a login URL. Even though, I personally, am not going to allow anyone login access, I still need to get the code response.
          I just wrote a quick a5w page and hand coded the variables in it. See Forming the URL in the url below. Make sure response_type is 'code' and that approval_prompt is 'force'. It needs to be force in order to get a refresh token. Going to the link you generate will bring you to a google login, then will return you back to whatever your redirect_uri is. (Make sure you set it up in your api's console)

          This will give you the code variable which we use in step 3
          Reference: https://developers.google.com/accoun...Auth2WebServer
        3. Now that we have the code variable, we need to exchange it for a refresh_token. (See Handling the Response in the ref url.) I do have some sample code for this one
          Code:
          function getRefreshTokenFromCode as p (redirect_uri as c)
          		'e.redirect_uri	
          		dim url as c = "https://accounts.google.com/o/oauth2/token?"
          		dim parameters as c = ""
          		
          		*concat(parameters,"code=&")
          		*concat(parameters,"client_id=&")
          		*concat(parameters,"client_secret=" + urlencode("") + "&")
          		if variable_exists("redirect_uri")
          			*concat(parameters,"redirect_uri=" + urlencode("")+ "&")
          		else
          			getRefreshTokenFromCode = "Redirect URI Required."
          		end if
          		*concat(parameters,"grant_type=authorization_code")
          		
          		response = http_post(url,parameters)
          		
          		'Do Some error checking, then decode from json
          		if response.parsed_headers.status_code != 200
          			getRefreshTokenFromCode = "Error" + response.body
          			end
          		end if
          		
          		dim json as p
          		json = json_parse(response.body)
          		
          		getRefreshTokenFromCode = json
          	end function
          What you want back from this POST call is refresh_token. SAVE THIS VARIABLE SOMEWHERE!!! You will need it to 'cash it in' for an access token (every 60 minutes)
          Reference: https://developers.google.com/accoun...Auth2WebServer
        4. OK, so you've got a refresh_token, now you need to use that to get an access_token. In order to do this, you can use something similar to this:
          Code:
          'Need to get new access token from the refresh token
          			dim url as c = "https://accounts.google.com/o/oauth2/token?"
          			dim parameters as c = ""
          			*concat(parameters,"refresh_token="+getRefreshToken()+"&")
          			*concat(parameters,"client_id=&")
          			*concat(parameters,"client_secret=&")
          			*concat(parameters,"grant_type=refresh_token")
          			
          			dim response as p = http_post(url,parameters)
          			'Decode response
          			if response.parsed_headers.status_code != 200
          				getAccessToken = "Error" + response.body
          			end if
          			
          			dim json as p = json_parse(response.body)
          			setAccessToken(json)
          This bit of code will get the access_token from google. YOU NEED TO SAVE THIS!!! It is good for the value in expires_in. (3600 seconds in my experience, (60 min). This is also something that needs to be saved. What I do is use a function 'getAccessToken()' that first checks the current time vs the expires_in time. If it's still valid it returns the access token, otherwise it uses the refresh token to get a new access token as well as a new expires_in time. getRefreshToken() is just a function call to lookup the refresh_token from the sql table.
        5. And we've now got a valid access token! We are now authenticated to the google api, and can make authenticated api calls.

        Comment


          #5
          Re: Google Calendar API

          Part Two
          ---
          Now that we've got a valid access_token, we can make authenticated calls to the API.
          1. This is where I am using php helper functions, but with the improved json_parse() in alpha, you won't need to. For this example, I'll do an events call to the API.
            THIS IS PHP NOT XBASIC!!!!!
            Code:
            //URL For List Events
            //https://developers.google.com/google-apps/calendar/v3/reference/events/list
            
            $url = "https://www.googleapis.com/calendar/v3/calendars/".$calendarId."/events";
            $url .= "?singleEvents=true";
            $url .= "&timeMin=".urlencode(date(DATE_ATOM,$start));
            $url .= "&timeMax=".urlencode(date(DATE_ATOM,$end));
            $url .= "&userIp=".urlencode($ip);
            
            $ch = curl_init( $url );
            	
            //Ask curl to return something from the server
            curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
            	
            //Turn off SSL Verification
            //TODO FIX HTTPS BY INSTALLING CERT
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
            	
            //Set the Authorization
            if(isset($access_token)){
            	$header = array(
            		"Authorization: Bearer " . $access_token
            	);
            	curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
            }
            $response = curl_exec( $ch );
            	
            curl_close( $ch );
            
            $response = json_decode($response, true);
            This php code could be improved upon in xbasic. For starters, xbasic has a http_post function that could handle my curls in php. Basically, all I'm doing is adding a header with the access_token in it for authentication. Like I said, eventually, I'll bring this in to alpha, but it won't be until January at the earliest.
          2. Now I've got a decoded json_array in the $response variable. This contains all the info I need in order to generate the events needed for display on my calendar :)
          3. Refer to https://developers.google.com/google...ce/events/list for information on the list events call

          Comment


            #6
            Re: Google Calendar API

            Wow thank you so much!!! I'll start getting into all this and let you know. Thank you again!!! You are totally awesome!!

            Comment


              #7
              Re: Google Calendar API

              Sparticuz,

              I've finally been trying to get this to work, and I just do not know where to begin still. At the moment, all I want to do is insert a new appointment into my google calendar from my alpha5 web app. I come from a desktop dev environment and have done really good working on my web app in A5, but I just don't know where to put what code.

              the username/password for the calendar would be hard coded into the request... I understand the PHP side of it (which I did some PHP programming but again, not an expert).

              In all the above, I was able to get step 1 done. lol For step 2, I realize that I have to create the a5w page, but I do not know when it is called, and how it correlates to anything else (except when google returns the authorization).

              Any chance of creating a short DEMO app on how to accomplish putting an event on a calendar?

              Comment


                #8
                Re: Google Calendar API

                Hi Spaticuz

                I was reading about this with interest. Did you write the new XBasic class ? If so do you have any further advice? thanks and best regards, Graeme Smith


                Originally posted by Sparticuz View Post
                I have alot of experience with it. In fact, I've been writing a XBasic class for it. I would HIGHLY recommend a few links from Google. https://developers.google.com/google.../v3/reference/ as well as https://developers.google.com/accounts/docs/OAuth2

                Start with the OAuth2 article if your app is going to need authentication. Ask any questions you want and I've more than likely dealt with it. I'm not quite ready to share my XBasic class in total (not quite 100% complete), but I will definitely share snippets to help you out.

                As for me, My app uses a Five different google accounts (for 5 different regions) and has between 4-7 individual calendars per account. A person can set an appointment by clicking a box and typing in a little bit of information. At that point, it saves the event to the correct calendar. (which is then available for syncing on smartphones). My code takes care of auth tokens (which must be refreshed every 60 minutes of use using a refresh token). I wrote this app before Alpha fixed their JSON implementation, so I use a 'man in the middle' PHP script to help with the JSON, but I've been meaning to convert it pure xbasic. I also use a jQuery calendar call FullCalendar (http://arshaw.com/fullcalendar/) which, when combined with one of my scripts, can also display events from Google calendar on my site.

                Ask away :)

                Comment


                  #9
                  Re: Google Calendar API

                  That's a negative. I knew someone would ask eventually. Feel free to ask any questions and I'll try to answer. (I have not cancelled writing it, just postponing it...)

                  Comment

                  Working...
                  X