1

I am using OAuth 2.0 Library for Google Spreadsheet for Meetup Api

Code.gs

function getMeetupService() {  
  return OAuth2.createService('meetup')

      // Set the endpoint URLs, which are the same for all Google services.
      .setAuthorizationBaseUrl('https://secure.meetup.com/oauth2/authorize')
      .setTokenUrl('https://secure.meetup.com/oauth2/access')

      // Set the client ID and secret, from the Google Developers Console.
      .setClientId('.....')
      .setClientSecret('......')

      // Set the name of the callback function in the script referenced
      // above that should be invoked to complete the OAuth flow.
      .setCallbackFunction('authCallback')

      // Set the property store where authorized tokens should be persisted.
      .setPropertyStore(PropertiesService.getUserProperties())

      .setTokenFormat(OAuth2.TOKEN_FORMAT.FORM_URL_ENCODED);

}
_eventId = null;
function startService(eventId) {
  var meetupService = getMeetupService();
  if (!meetupService.hasAccess()) {
    var authorizationUrl = meetupService.getAuthorizationUrl();
    return authorizationUrl;

  } else {
   //Yet to decide
  }
  return 123;
}

function authCallback(request) {
  var meetupService = getMeetupService();
  var isAuthorized = meetupService.handleCallback(request);
  if (isAuthorized) {
    //getAllDetails(_eventId);
  } else {
    return HtmlService.createHtmlOutput('Denied. You can close this tab');
  }
}

Sidebar.html

    $(function() {
      checkService();
});
function checkService() {
    google.script.run
    .withSuccessHandler(function(url) {
        if(url) {
        $('body').append('<a href="'+url+'" target="_blank">Click here to Login into Meetup</a>');
           $('#run-get-details').attr("onclick", 'window.open("' + url + '")');
        } else {
           $('#run-get-details').attr("url", '');
        }
        $('#run-get-details').prop("disabled", false);
    })
    .withFailureHandler(failureHandler)
    .startService($("#eventId").val());
}
function authCallback(request) {
  alert(123);
}

Everything seems to be working till the link. Once the link is clicked it opens the authentication window of the meetup exactly i want. But then once I authorize the app in meetup and when it gets redirected to script.google.com

https://script.google.com/a/macros/{domain}/d/{PROJECT_ID}/usercallback?code={code}&state=ADEpC8wvspQd-+VXyQ0mOhYNenFu9Ib08hK6xfJ2gNJwcTxrIB4nVfphDyhejUHEMdgD0OhtwdcEs46KdhUZMD-Ekwftj3bzXwdi-mKc8PLKd7SsAYYqE-ZVZD2tm1HmyxtKYJCkoeg7R1K5DIMedYp38BiJ4F2Hbtei34fEdveObQhMSMDt1f2ufrmDzGh5W+fxdXMEmrfeCINO23hC8yV0JRXVDkErL3t8pQih8DicQoY6k2uqHThK8BqfSioBkgPZ0SPvj3Krtpgj9R+XWGtPqRRAwPum4k8etMROvy2DLT1ENNJdrVw

But then its throwing the error

The state token is invalid or has expired. Please try again.

Someone please help me in this.

Vinod Gubbala
  • 676
  • 6
  • 16

1 Answers1

0

So looking into this a bit further I found the issue. The Meetup server is changing the state token. If you copy your token from getAuthorizationUrl() and paste it into the state parameter in the url of the bad callback the Auth flow will successfully continue.

State Token made by Apps Script

ADEpC8zI8-E38GrIi2sB5Pf1xK2Hn-6XQ-SJLa0gmxos6z-hbvedTJ2UvXzSJxXbE_NfJlpHkOsjN4DLJ0sOGsYIZpTBc3OpAMWuoj-8UjUuKcTs1htZknyzv0QX9pPe-McxB_MC1fbGBjvrwEGP5_58tQdfRf3K70LURbe0cZ2qx_YK5xxN2qE

Returned State Token

ADEpC8zI8-E38GrIi2sB5Pf1xK2Hn-6XQ-SJLa0gmxos6z-hbvedTJ2UvXzSJxXbE+NfJlpHkOsjN4DLJ0sOGsYIZpTBc3OpAMWuoj-8UjUuKcTs1htZknyzv0QX9pPe-McxB+MC1fbGBjvrwEGP5+58tQdfRf3K70LURbe0cZ2qx+YK5xxN2qE
Spencer Easton
  • 5,642
  • 1
  • 16
  • 25
  • I posted an issue on their github page. Nothing that can be done on the Apps Script side I don't think. You can do the paste the currect state into the callback url method if you need a token for testing. It worked for me. – Spencer Easton May 27 '15 at 17:50