1

我想获取域中所有用户的日历详细信息。我正在尝试通过使用 UrlFetchApp 并将获取请求发送到服务器来做到这一点。

var urlFetch = UrlFetchApp.fetch(url, fetchArgs);

我为此传递了所有必需的参数。但它给出了302 Moved Temporarily服务器错误。有时它的工作,但并非总是如此。要消除此问题,我必须再次向服务器发送具有相同内容和参数的 get 请求。当发送第一个获取请求时,它返回一个 url,一个会话 id 被附加到它上面。所以我需要用这个新的 url 发送一个请求。

我为此使用了以下代码:

function getCalender(){
    var users = UserManager.getAllUsers(); 
     var scope = 'https://www.google.com/calendar/feeds/';
     var fetchArgs = googleOAuth_('calender', scope);

     for(i=0;i<users.length;i++ ){
          var url ='https://www.google.com/calendar/feeds/'+users[i].getEmail()+'/private/full';

          try{
          var urlFetch=UrlFetchApp.fetch(url,fetchArgs)

         }
          catch(err){
            Logger.log(err)

          }
      }
}

function googleOAuth_(name,scope) {
  var oAuthConfig = UrlFetchApp.addOAuthService(name);
  oAuthConfig.setRequestTokenUrl("https://www.google.com/accounts/OAuthGetRequestToken?scope="+scope);
  oAuthConfig.setAuthorizationUrl("https://www.google.com/accounts/OAuthAuthorizeToken");
  oAuthConfig.setAccessTokenUrl("https://www.google.com/accounts/OAuthGetAccessToken");
  oAuthConfig.setConsumerKey("");
  oAuthConfig.setConsumerSecret("");
  return {oAuthServiceName:name, 
  oAuthUseToken:"always",
  content:'application/atom+xml', 
  method:"GET",
  Authorization:'GoogleLogin auth=?'};
}

当我打印错误值时,它给出:

Exception: Request failed for  returned code 302. Server response: <HTML>
<HEAD>
<TITLE>Moved Temporarily</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Moved Temporarily</H1>
The document has moved <A HREF="https://www.google.com/calendar/feeds/<email-id>/private/full?gsessionid=y1oQCjGH3LqTKJgyh9BlhA">here</A>.
</BODY>
</HTML>

我想让这个移动的 id 发送一个带有新 url 的新请求。请给我任何想法来解决这个问题!

4

1 回答 1

0

This would be done by converting server response in a string, then split the string to get special text from the paragraph.

于 2012-10-05T11:10:49.410 回答