Oauth2 authentication for podio

EzyOauth2 has now been superseded by Goa, so this document is for legacy information. For more information see OAuth2 for Apps Script in a few lines of code. If you are using EzyOauth2, it's easy to migrate. If you are starting up, consider using Goa instead - it's easier and has more features.

In EzyOauth2 - taking some pain out of Apps Script API authentication, I provided a library to simplify oAuth2, then in EzyOauth2 patterns I showed simple patterns for creating apps. Multiple oAuth2 authentication packages showed how to create multiple authentication packages in the same project. 

Here's a new one - this time for the podio service. 

For other authentication packages, see 
only a few minor modifications are needed from the podio version shown below.

Getting started

You need to set up your application - this time in the podio developers console. This is a lot simpler than some other consoles, but the principle in the same. You'll get a client id and a secret. The podio API authentication is less complex than others - you don't need to register a redirect URI, and there aren't even any scopes to set. 

Package Names

You need to add these to your one time credential storing function.  I've called it podio.

function oneTimeSetProperties () {
  setAuthenticationPackage_ ({ 
    clientId: "xxx",               
    scopes : [],
    service: "podio",
    packageName: "podio"

  setAuthenticationPackage_ ({ 
    clientId : "1046xxxvum.apps.googleusercontent.com",
    clientSecret : "ejixxx-hRFN",
    scopes : ['https://www.googleapis.com/auth/datastore','https://www.googleapis.com/auth/userinfo.email'],
    service: 'google'
  setAuthenticationPackage_ ({ 
    clientId: "avxxxcfs",                                             // linkedin call it apiKey
    clientSecret:"Ji7Oxxx",                                      // linkedin call it secretKey
    scopes : ["r_network"],
    service: "linkedin",
    packageName: "linkedinNetwork"
  setAuthenticationPackage_ ({ 
    clientId: "0ecxxx0983ce",               
    scopes : ["non-expiring"],
    service: "soundcloud",
    packageName: "soundcloud"


Service names

I already added the podio service to the cEzyOauth2 library.

    var PACKAGELIST = [
      { name:'google',
          authUrl : "https://accounts.google.com/o/oauth2/auth",
          tokenUrl: "https://accounts.Google.Com/o/oauth2/token",
          refreshUrl: "https://accounts.google.com/o/oauth2/token"  
      { name:'linkedin',
          authUrl : "https://www.linkedin.com/uas/oauth2/authorization",
          tokenUrl: "https://www.linkedin.com/uas/oauth2/accessToken",
          refreshUrl: "https://www.linkedin.com/uas/oauth2/authorization" 
      { name:'soundcloud',
          authUrl : "https://soundcloud.com/connect",
          tokenUrl: "https://api.soundcloud.com/oauth2/token",
          refreshUrl: "https://api.soundcloud.com/oauth2/token" 
      { name:'podio',
          authUrl : "https://podio.com/oauth/authorize",
          tokenUrl: "https://podio.com/oauth/token",
          refreshUrl: "https://podio.com/oauth/token" 

A web application.

The only difference between this and the example shown in EzyOauth2 patterns, is that I am calling different function names and package name. I don't actually use podio, so I found the actual podio API fiddly, even though the authentication part worked first time. 

 * this is your web app
 * @param {object} webapp param object
 * return {HtmlOutput} 

function doGet (e) {
  return doGetPattern(e, constructConsentPodio, doSomethingPodio,"podio") ;

 * tailor your consent screen with an html template
 * @param {string} consentUrl the url to click to provide user consent
 * @return {string} the html for the consent screen
function constructConsentPodio (consentUrl) {
  return '<a href = "' + consentUrl + '">Authenticate to Podio</a> ';

 * this is your main processing - will be called with your access token
 * @param {string} accessToken - the accessToken
function doSomethingPodio (accessToken) {
   var options = {
     method: "GET"

  //var result = UrlFetchApp.fetch("https://api.podio.com/app/?exclude_demo=true&limit=4&order=score?oauth_token="+accessToken, options);
  var result = UrlFetchApp.fetch("https://api.podio.com/calendar/?date_from=2014-05-01&date_to=2014-07-30&oauth_token="+accessToken, options);
  return HtmlService.createHtmlOutput (' it worked' + result.getContentText());



Once your credentials are set up, all you have to do is pass the function that does the work to doGetPattern(e, constructConsentPodio, doSomethingPodio,"podio")   and it will be called with a fresh accessCode. Simple!