Aktualizacja wsadowa do arkusza kalkulacyjnego za pomocą Google GData API przy użyciu 2 legged konta domeny OAUTH / OPEN ID

Ok, weekend jest na to nakręcony - oto moja ostatnia rozmowa w niedzielę o pomoc.

Aplikacja Google Marketplace, która musi korzystać z 2 legged OAUTH aproach, musi napisać 50K rekordów do arkusza kalkulacyjnego Google Doc. Mogę tworzyć, zmieniać rozmiar, zmieniać nazwy i zapisywać rekordy w arkuszu kalkulacyjnym. Pisanie 100 wierszy zajmuje nawet minutę, więc muszę użyć aktualizacji wsadowej. Nie można uruchomić aktualizacji wsadowej. Poniższy kod jest moją najlepszą próbą - ciągle otrzymuję „Nieprawidłowy token - Nieprawidłowy token 401”. Cały przykładowy kod dostępny jest dla trójstronnego oautha - ale nie mogę poprosić użytkownika o zatwierdzenie aplikacji, ponieważ jest to aplikacja rynkowa

Byłoby wspaniale znaleźć przykład aktualizacji arkusza wsadowego przy użyciu openid i 2LO

      final String SCOPE = "https://spreadsheets.google.com/feeds/spreadsheets/private/full";
        SpreadsheetService spreadsheetService;
        String consumerKey = getInitParameter("consumer_key");
        String consumerSecret = getInitParameter("consumer_secret");
        GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
        oauthParameters.setOAuthConsumerKey(consumerKey);
        oauthParameters.setOAuthConsumerSecret(consumerSecret);
        oauthParameters.setOAuthType(OAuthParameters.OAuthType.TWO_LEGGED_OAUTH);
        oauthParameters.setScope(SCOPE);
        OAuthSigner signer = new OAuthHmacSha1Signer();
        spreadsheetService = new SpreadsheetService("nimbits-com");
        String title = entity.getName().getValue();

        try {

            spreadsheetService.setOAuthCredentials(oauthParameters, signer);
            spreadsheetService.setProtocolVersion(SpreadsheetService.Versions.V3);
            SpreadsheetQuery query = new SpreadsheetQuery(new URL(SCOPE));
            query.addCustomParameter(new Query.CustomParameter("xoauth_requestor_id", user.getEmail().getValue()));
            query.setTitleQuery(title);
            SpreadsheetFeed feed =  spreadsheetService.query(query, SpreadsheetFeed.class);


//works fine up to this point, I get the feed and spreadsheet.

            if (feed != null && ! feed.getEntries().isEmpty()) {

                com.google.gdata.data.spreadsheet.SpreadsheetEntry wsEntry = feed.getEntries().get(0);
                WorksheetEntry sheet = wsEntry.getWorksheets().get(0);
                CellFeed batchRequest = new CellFeed();
                String batchId = "R" + 2 + "C" + 1;


                URL entryUrl = new URL(sheet.getCellFeedUrl().toString() + "/" + batchId);

//Invalid TOKEN error here, trying to get the entry. 
CellEntry batchOperation = spreadsheetService.getEntry(entryUrl, CellEntry.class);
                batchOperation.setService(spreadsheetService);
                batchOperation.changeInputValueLocal("test");
                BatchUtils.setBatchId(batchOperation, batchId);
                BatchUtils.setBatchOperationType(batchOperation, BatchOperationType.UPDATE);
                batchRequest.getEntries().add(batchOperation);


                CellFeed cellFeed = spreadsheetService.getFeed(sheet.getCellFeedUrl(), CellFeed.class);
                Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH, Link.Type.ATOM);
                URL batchUrl = new URL(batchLink.getHref());
                spreadsheetService.batch(batchUrl, batchRequest);
            }
        } catch (MalformedURLException e) {
            LogHelper.logException(this.getClass(), e);
            throw new NimbitsException(e);

        } catch (ServiceException e) {
            LogHelper.logException(this.getClass(), e);
            throw new NimbitsException(e);
        } catch (IOException e) {
            LogHelper.logException(this.getClass(), e);
            throw new NimbitsException(e);
        } catch (OAuthException e) {
            LogHelper.logException(this.getClass(), e);
            throw new NimbitsException(e);
        }

Ten przykład próbuje po prostu napisać jeden rekord w partii. Zmieniłem rozmiar arkusza kalkulacyjnego i wygląda on dobrze. Nie widzę, jak ustawić token lub wypełnić to żądanie za pomocą 2LO. Próbowałem dodać xoauth_requestor_id do adresów URL.

edytuj od kiedy zacząłem nagrodę:

Ten fragment kodu działa doskonale i dodaje 1 wiersz do istniejącego arkusza kalkulacyjnego z uwierzytelnieniem 2LO, które posiadam. Potrzebuję go zmodyfikować, aby szybko uruchomić 50 000 wierszy.

 @Override
public void addSpreadsheetHeader(Entity entity) throws NimbitsException {
    final User user = UserServiceFactory.getServerInstance().getHttpRequestUser(
            this.getThreadLocalRequest());


    SpreadsheetService spreadsheetService;
    String consumerKey = getInitParameter("consumer_key");
    String consumerSecret = getInitParameter("consumer_secret");
    GoogleOAuthParameters oauthParameters = new GoogleOAuthParameters();
    oauthParameters.setOAuthConsumerKey(consumerKey);
    oauthParameters.setOAuthConsumerSecret(consumerSecret);
    spreadsheetService = new SpreadsheetService("nimbits-com");


    //  SpreadsheetEntry entry = new SpreadsheetEntry();
    String title = entity.getName().getValue();
    //  entry.setTitle(TextConstruct.plainText(title));



    try {
        spreadsheetService.setOAuthCredentials(oauthParameters, new OAuthHmacSha1Signer());
        SpreadsheetQuery query = new SpreadsheetQuery(new URL("https://spreadsheets.google.com/feeds/spreadsheets/private/full"));
        query.addCustomParameter(new Query.CustomParameter("xoauth_requestor_id", user.getEmail().getValue()));

        query.setTitleQuery(title);
        SpreadsheetFeed feed =  spreadsheetService.query(query, SpreadsheetFeed.class);
        if (feed != null && ! feed.getEntries().isEmpty()) {
            com.google.gdata.data.spreadsheet.SpreadsheetEntry wsEntry = feed.getEntries().get(0);
            WorksheetEntry sheet = wsEntry.getWorksheets().get(0);
            URL cellFeedUrl= sheet.getCellFeedUrl ();
            CellFeed cellFeed= spreadsheetService.getFeed (cellFeedUrl, CellFeed.class);
            CellEntry cellEntry;

            cellEntry= new CellEntry (1, 1, "Timestamp");
            cellFeed.insert (cellEntry);

            cellEntry= new CellEntry (1, 2, "Value");
            cellFeed.insert (cellEntry);

            cellEntry= new CellEntry (1, 3, "Latitude");
            cellFeed.insert (cellEntry);

            cellEntry= new CellEntry (1, 4, "Longitude");
            cellFeed.insert (cellEntry);

            cellEntry= new CellEntry (1, 5, "Annotation");
            cellFeed.insert (cellEntry);

            cellEntry= new CellEntry (1, 6, "Data");
            cellFeed.insert (cellEntry);

        }



    } catch (MalformedURLException e) {
        LogHelper.logException(this.getClass(), e);
        throw new NimbitsException(e);

    } catch (ServiceException e) {
        LogHelper.logException(this.getClass(), e);
        throw new NimbitsException(e);
    } catch (IOException e) {
        LogHelper.logException(this.getClass(), e);
        throw new NimbitsException(e);
    } catch (OAuthException e) {
        LogHelper.logException(this.getClass(), e);
        throw new NimbitsException(e);
    }


}

questionAnswers(1)

yourAnswerToTheQuestion