Repeatedly aking me to authorize my app on every call, lists in approved applications


#1

Using Google Script to make a very simple personal use RSS dump of certain timelines and searches.

Since Friday, every time I make a request I’m asked to authorize the app, afterwards the current request gets stuck and I have to make another request… which also requests authorization. The App shows up in my list of approved apps just fine. I’ve tried revoking access and reauthorizing, then trying to access data, and again it asks me to authorize the app.

I’ve also tried revoking the app, generating a new ConsumerKey and ConsumerSecretKey, updating my code, reauthorizing my app, and trying a request again. I’ve done this twice with no change in outcome.

I’ve tried everything I can think of, and still coming up dry, so hopefully someone can help. My code is included below.

function doGet(e) {
   
  var a = e.parameter.action;
  var q = e.parameter.q;
  
  var feed;  
  
  switch (a) 
  {
    case "timeline": 
      feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + q + "&count=200";
      break;
    case "timelinenr":
      feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + q + "&count=200&exclude_replies=true";
      break;
    case "timelinenrt":
      feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + q + "&count=200&include_rts=false";
      break;
    case "timelinenrrt":
      feed = "https://api.twitter.com/1.1/statuses/user_timeline.json?screen_name=" + q + "&count=200&exclude_replies=true&include_rts=false";
      break;
    case "search":
      feed = "https://api.twitter.com/1.1/search/tweets.json?q=" + encodeString (q);
      break;
    case "favorites":
      feed = "https://api.twitter.com/1.1/favorites/list.json?screen_name=" + q;
      break;
    case "list":
      var i = q.split("/");
      feed = "https://api.twitter.com/1.1/lists/statuses.json?slug=" + i[1] + "&owner_screen_name=" + i[0];
      break;
    default:
      feed = "https://api.twitter.com/1.1/statuses/user_timeline.json";
      break;
  }
  
  var rss = JSONtoRSS ( feed, a, q );
  
  return ContentService.createTextOutput(rss)
    .setMimeType(ContentService.MimeType.RSS);
}


function JSONtoRSS(json, type, key) {

  var ConsumerKey = "AAA";
  var ConsumerSecret = "BBB";
  
  var oauthConfig = UrlFetchApp.addOAuthService("twitter");
  oauthConfig.setAccessTokenUrl("https://api.twitter.com/oauth/access_token");
  oauthConfig.setRequestTokenUrl("https://api.twitter.com/oauth/request_token");
  oauthConfig.setAuthorizationUrl("https://api.twitter.com/oauth/authorize");
  oauthConfig.setConsumerKey(ConsumerKey);
  oauthConfig.setConsumerSecret(ConsumerSecret);
  
  var options =
  {
    "method": "get",
    "oAuthServiceName":"twitter",
    "oAuthUseToken":"always"
  };
    
  try {

    var result = UrlFetchApp.fetch(json, options);    
    //Code never reached beyond this point!
    
    if (result.getResponseCode() === 200) {
      
      var tweets = Utilities.jsonParse(result.getContentText());
      
      if (type == "search") 
        tweets = tweets.statuses;
      
      if (tweets) {
                
        var len = tweets.length;
        
        var rss = "";
        
        if (len) {
          
          rss  = '<?xml version="1.0"?><rss version="2.0">';

          if (type == "search") {
            rss += ' <channel><title>Twitter Search: ' + key + '</title>';
          } else {
             rss += ' <channel><title>@' + key + '</title>';
         }

          rss += ' <link>' + htmlentities ( json ) + '</link>';
          rss += ' <pubDate>' + new Date() + '</pubDate>';

          for (var i=0; i<len; i++) {
            
            var sender = tweets[i].user.screen_name;
            if (typeof(tweets[i].retweeted_status) != "undefined") {
              var tweet  = "RT @" + tweets[i].retweeted_status.user.screen_name + ": " + htmlentities ( tweets[i].retweeted_status.text );
            } else {
              var tweet  = htmlentities ( tweets[i].text );
            }
            
            rss += "<item><title>" + sender + ": " + tweet + "</title>";
            rss += " <author>" + tweets[i].user.name + " (@" + sender + ")</author>";
            rss += " <pubDate>" + tweets[i].created_at + "</pubDate>";
            rss += " <guid isPermaLink='false'>" + tweets[i].id_str + "</guid>";
            rss += " <link>https://twitter.com/" + sender + "/statuses/" + tweets[i].id_str + "</link>";
            rss += " <description>" + tweet + "</description>";
            rss += "</item>";            
            
          }
          
          rss += "</channel></rss>";
          
          return rss;
          
        }
        
      }
      
    }
    
  } catch (e) {
    Logger.log(e.toString());
  }
  
}

function encodeString (q) {

  var str =  encodeURIComponent(q);
   str = str.replace(/!/g,'%21');
   str = str.replace(/\*/g,'%2A');
   str = str.replace(/\(/g,'%28');
   str = str.replace(/\)/g,'%29');
   str = str.replace(/'/g,'%27');
   return str;

}

function htmlentities(str) {

  str = str.replace(/&/g, "&amp;");
  str = str.replace(/>/g, "&gt;");
  str = str.replace(/</g, "&lt;");
  str = str.replace(/"/g, "&quot;");
  str = str.replace(/'/g, "&#039;");
  return str;

}

#2

Still broken, still nothing I try works…