Howdy, I'm brand new to GAE/Java dev, and wish to ask a few questions about a simple test code fragment I just deployed. This (very simple) code fragment might help someone implement OAuth when integrating GAE with Google App Script. I've seen parts of it in a few places, but never in a complete example. I needed a way to authenticate a Google Docs user with my application to restrict access.
The code on the Google App Script side of things: /***************/ function authentication() { var oAuthConfig = UrlFetchApp.addOAuthService("google"), utc = (new Date()).toUTCString(); oAuthConfig.setAccessTokenUrl("https://<APP-ID>.appspot.com/_ah/ OAuthGetAccessToken"); oAuthConfig.setRequestTokenUrl("https://<APP-ID>.appspot.com/_ah/ OAuthGetRequestToken"); oAuthConfig.setConsumerKey('anonymous'); oAuthConfig.setConsumerSecret('anonymous'); var requestData = { "method": "GET", "oAuthServiceName": "google", "oAuthUseToken": "always" }; var response = UrlFetchApp.fetch('http://<APP-ID>.appspot.com/<THE- URI>', requestData).getContentText(); var sheet = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0]; var lastRow = sheet.getLastRow(); sheet.getRange(lastRow + 1, 1).setValue(utc); sheet.getRange(lastRow + 1, 2).setValue(response); } /***************/ On GAE: /***************/ package mypackage; import java.io.IOException; import java.util.Date; import javax.servlet.http.*; import com.google.appengine.api.users.User; import com.google.appengine.api.oauth.OAuthService; import com.google.appengine.api.oauth.OAuthServiceFactory; public class AppScriptServerServlet extends HttpServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { User user = null; Date date = new Date(System.currentTimeMillis()); try { OAuthService oauth = OAuthServiceFactory.getOAuthService(); user = oauth.getCurrentUser(); resp.getWriter().println("Request time: " + date.toString() + " User: " + user.getNickname()); } catch (Exception e) { resp.getWriter().println("Request time: " + date.toString() + " Exception: " + e.toString()); } } } /***************/ My 2 questions: 1. I have set up a time driven trigger on GAS to execute the script every minute. It seems I get current Date values from the GAE app every 6 minutes +-6 seconds (very monotonously): Fri, 01 Apr 2011 20:05:12 GMT :::::: "Request time: Fri Apr 01 20:01:14 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:06:12 GMT :::::: "Request time: Fri Apr 01 20:01:14 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:07:12 GMT :::::: "Request time: Fri Apr 01 20:07:14 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:08:12 GMT :::::: "Request time: Fri Apr 01 20:07:14 UTC 2011 User: u...@domain.com" . . . Fri, 01 Apr 2011 20:11:12 GMT :::::: "Request time: Fri Apr 01 20:07:14 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:12:12 GMT :::::: "Request time: Fri Apr 01 20:07:14 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:13:12 GMT :::::: "Request time: Fri Apr 01 20:13:15 UTC 2011 User: u...@domain.com" Fri, 01 Apr 2011 20:14:12 GMT :::::: "Request time: Fri Apr 01 20:13:15 UTC 2011 User: u...@domain.com" What am I doing wrong? (if it's Java related, very sorry, my last Java classes date back more than 6 minutes ago); 2. This very simple app generates a lot of CPU time. From the GAE Dashboard: /<MY-URI> :::::: 36 [requests] :::::: 1741 (0) [Avg CPU (API)] :::::: 100% [% CPU] The Quota Details page is more reassuring: my immediate CPU Quota is "Okay". Am I right to think this is a discrepancy? Aren't both of these values a short-time average (over a minute)? I guess I'll trust the value I like best: "Okay" Thanks -- You received this message because you are subscribed to the Google Groups "Google App Engine for Java" group. To post to this group, send email to google-appengine-java@googlegroups.com. To unsubscribe from this group, send email to google-appengine-java+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/google-appengine-java?hl=en.