2011-06-15 25 views
0

我正在嘗試通過編程方式向Google應用引擎進行身份驗證。 我試着從「GAE-APP-經理」項目中的代碼示例,但它失敗:如何以編程方式向Google應用引擎(使用Java)進行身份驗證?

tmp>java -jar net.sf.gae-app-manager-0.0.1-jar-with-dependencies.jar [email protected] mypassword appname 
Exception in thread "main" java.lang.Exception: Did not find ACSID cookie 
     at net.sf.gaeappmanager.google.LogonHelper.loginToGoogleAppEngine(LogonHelper.java:85) 
     at net.sf.gaeappmanager.google.appengine.Manager.retrieveAppQuotaDetails(Manager.java:34) 
     at net.sf.gaeappmanager.google.appengine.Main.main(Main.java:55) 

任何想法?我能夠獲得令牌,但沒有cookie。 代碼(從GAE-APP-Manager項目採取 - http://gae-app-manager.git.sourceforge.net/git/gitweb.cgi?p=gae-app-manager/gae-app-manager;a=blob;f=src/main/java/net/sf/gaeappmanager/google/LogonHelper.java;h=8e09a6d7f864c29b10847ac7fd2eeab2d3e561e6;hb=HEAD):

List<NameValuePair> nvps = new ArrayList<NameValuePair>(); 
    52       nvps.add(new BasicNameValuePair("accountType", "HOSTED_OR_GOOGLE")); 
    53       nvps.add(new BasicNameValuePair("Email", userid)); 
    54       nvps.add(new BasicNameValuePair("Passwd", password)); 
    55       nvps.add(new BasicNameValuePair("service", "ah")); 
    56       nvps.add(new BasicNameValuePair("source", source)); 
    57 
    58       HttpPost post = new HttpPost(
    59           "https://www.google.com/accounts/ClientLogin"); 
    60       post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); 
    61 
    62       HttpResponse response = client.execute(post); 
    63 
    64       if (response.getStatusLine().getStatusCode() != 200) { 
    65         throw new Exception("Error obtaining ACSID"); 
    66       } 
    67 
    68       String authToken = getAuthToken(response.getEntity().getContent()); 
    69 
    70       post.abort(); 
    71 
    72       HttpGet get = new HttpGet(
    73           "https://appengine.google.com/_ah/login?auth=" + authToken); 
    74 
    75       response = client.execute(get); 
    76 
    77       for (Cookie cookie : client.getCookieStore().getCookies()) { 
    78         if (cookie.getName().startsWith("ACSID")) { 
    79           return cookie.getValue(); 
    80         } 
    81       } 
    82 
    83       get.abort(); 
    84 
    85       throw new Exception("Did not find ACSID cookie"); 

感謝,

+0

能否請你幫我在這裏http://stackoverflow.com/questions/23306993/google-apps-customized-google-login-page- in-appspot – 2014-04-28 15:25:26

回答

0

爲了解決這個問題,用「SACSID」而不是「ACSID」

+1

您能否詳細說明一下? – latestVersion 2013-12-20 03:46:02

1

你有沒有使用OAuth support,而不是試圖登錄的網頁考慮客戶會嗎?每個App Engine應用程序都可以充當OAuth提供程序,只需要很少的工作就可以在服務器端進行設置。

+0

我會嘗試使用OAuth - 它是否允許我訪問任何允許使用的https站點(如使用HttpClient),還是僅限於GAE中的特定區域?謝謝。 – Lin 2011-06-16 10:21:19

+0

@李我不知道我明白。您正試圖向App Engine驗證客戶端,不是嗎?其他網站與它有什麼關係? – 2011-06-17 00:28:46

+0

我想知道如果我可以使用相同的方法連接到Gmail和其他穀子子域。 – Lin 2011-06-19 18:35:01

相關問題