1

我正在为Meetup Api使用 Google 电子表格的OAuth 2.0 库

代码.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');
  }
}

边栏.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);
}

一切似乎都在工作,直到链接。单击链接后,它将完全打开我想要的聚会的身份验证窗口。但是,一旦我在聚会中授权该应用程序并将其重定向到 script.google.com

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

但随后它抛出了错误

状态令牌无效或已过期。请再试一次。

有人请帮助我。

4

1 回答 1

0

所以进一步研究这个问题,我发现了这个问题。Meetup 服务器正在更改状态令牌。如果您从 getAuthorizationUrl() 复制令牌并将其粘贴到错误回调的 url 中的 state 参数中,则身份验证流程将成功继续。

Apps 脚本制作的状态令牌

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

返回状态令牌

ADEpC8zI8-E38GrIi2sB5Pf1xK2Hn-6XQ-SJLa0gmxos6z-hbvedTJ2UvXzSJxXbE+NfJlpHkOsjN4DLJ0sOGsYIZpTBc3OpAMWuoj-8UjUuKcTs1htZknyzv0QX9pPe-McxB+MC1fbGBjvrwEGP5+58tQdfRf3K70LURbe0cZ2qx+YK5xxN2qE
于 2015-05-27T14:40:16.017 回答