【问题标题】:How to get value from HTML tag stored in a variable?如何从存储在变量中的 HTML 标记中获取值?
【发布时间】:2012-09-29 14:58:19
【问题描述】:

我想获取域中所有用户的日历详细信息。我正在尝试通过使用 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 的新请求。 请给我任何想法来解决这个问题!

【问题讨论】:

    标签: html xml google-apps-script


    【解决方案1】:

    这可以通过将服务器响应转换为字符串,然后拆分字符串以从段落中获取特殊文本来完成。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-02-18
      • 2013-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      相关资源
      最近更新 更多