0

我正在关注本指南: http ://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html

我只需要检索一个令牌并使用它来获取文档列表,所以我使用 AuthSub 来获取一个单次使用令牌,这似乎有效:我得到一个这样的字符串

1/BM14a4NnfKf........

现在我正在尝试这样做:http ://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html#Versioning

1) 指定版本

2) 检索文档列表

我在一个名为 TokenServiceImpl 的类中管理这些函数:

package mui.server.services;

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import mui.client.services.TokenService;

import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gdata.client.docs.DocsService;
import com.google.gdata.client.http.AuthSubUtil;
import com.google.gdata.data.docs.DocumentListEntry;
import com.google.gdata.data.docs.DocumentListFeed;
import com.google.gdata.util.AuthenticationException;
import com.google.gdata.util.ServiceException;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class TokenServiceImpl extends RemoteServiceServlet implements
        TokenService {

    private static final long serialVersionUID = 1L;

    String nextUrl = "";
    String scope = "https://docs.google.com/feeds/";
    boolean secure = false; // set secure=true to request secure AuthSub tokens
    boolean session = true;
    String authSubUrl = "";

    @Override
    public String getToken(String requestUri) {
        nextUrl = requestUri;
        authSubUrl = AuthSubUtil.getRequestUrl(nextUrl, scope, secure, session);

        return ", clicca <a href='" + authSubUrl
                + "'>qui</a> per regalarmi un token! (esempio Google Docs)";

    }

    @Override
    public String getDocsInfo(String token) {
        String elenco=", grazie del token, eccolo qui:<br> " + token + "<br>";

        DocsService client = new DocsService("yourCo-yourAppName-v1");
        client.setProtocolVersion(DocsService.Versions.V2);


        try {
            URL feedUri = new URL(
                    "https://docs.google.com/feeds/documents/private/full/");
            DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);

        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (ServiceException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


        return elenco;
    }


}

但在 getDocsInfo 方法(获取字符串“token”,之前检索到的令牌)中只有一行

DocumentListFeed feed = client.getFeed(feedUri, DocumentListFeed.class);

给我错误:

22-gen-2012 11.14.19 com.google.appengine.repackaged.org.apache.http.impl.client.DefaultRequestDirector handleResponse
AVVERTENZA: Authentication error: Unable to respond to any of these challenges: {googlelogin=WWW-Authenticate: GoogleLogin realm="http://www.google.com/accounts"}
com.google.gdata.util.AuthenticationException: OK
<HTML>
<HEAD>
<TITLE>Authorization required</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Authorization required</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

    at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:600)
    at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:563)
    at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:552)
    at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:530)
    at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:535)
    at com.google.gdata.client.Service.getFeed(Service.java:1135)
    at com.google.gdata.client.Service.getFeed(Service.java:998)
    at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
    at com.google.gdata.client.Service.getFeed(Service.java:1017)
    at mui.server.services.TokenServiceImpl.getDocsInfo(TokenServiceImpl.java:52)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
    at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:569)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:208)
    at com.google.gwt.user.server.rpc.RemoteServiceServlet.processPost(RemoteServiceServlet.java:248)
    at com.google.gwt.user.server.rpc.AbstractRemoteServiceServlet.doPost(AbstractRemoteServiceServlet.java:62)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.tools.development.HeaderVerificationFilter.doFilter(HeaderVerificationFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.BackendServersFilter.doFilter(BackendServersFilter.java:97)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.appengine.tools.development.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:78)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:362)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)

我错过了什么?我真的很困惑...我一开始就知道这一切,也许这很愚蠢...但这不正是指南中写的内容吗?在这个例子中 http://code.google.com/intl/it-IT/apis/documents/docs/2.0/developers_guide_java.html#ListDocs 我需要在哪里使用我检索到的令牌?

4

1 回答 1

0

还需要两个步骤:

1)将令牌更改为“sessionToken”:

    String sessionToken = AuthSubUtil.exchangeForSessionToken(token, null);

2)将令牌关联到客户端:

    DocsService client = new DocsService("yourCo-yourAppName-v1");
    client.setAuthSubToken(sessionToken);
于 2012-01-23T10:52:58.703 回答