Hi

I am new at using the OAuth process. I am using the 2 legged process
to get the OAuth done.
I am getting the following exception. This error has really wasted my
two weeks. Please help me out.


I am using the 2legged OAuth process to authenticate the DocsService
and SpreadsheetService.
My code snippet is

DocsService client = new DocsService("yourCo-yourAppName-v1");
        SpreadsheetService service = new SpreadsheetService("yourCo-
yourAppName-v1");

String CONSUMER_KEY = "THE_CONSUMER_KEY";
                String CONSUMER_SECRET = "THE_SECRET_KEY";

                GoogleOAuthParameters oauthParameters = new 
GoogleOAuthParameters();
                oauthParameters.setOAuthConsumerKey(CONSUMER_KEY);
                oauthParameters.setOAuthConsumerSecret(CONSUMER_SECRET);

        
oauthParameters.setOAuthType(OAuthParameters.OAuthType.TWO_LEGGED_OAUTH);
                try {
                        client.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
                        service.setOAuthCredentials(oauthParameters, new
OAuthHmacSha1Signer());
                } catch (OAuthException e1) {
                        // TODO Auto-generated catch block
                        e1.printStackTrace();
                }

Now i try to update cells using batch process using the code below,
Here cellInfo is the my class which has cell row and col info and cell
address such as R1C1.
and usermail is something [email protected]

private void insertCellBatchProcess(SpreadsheetEntry sp
                        List<CellInfo> cellInfos, String userEmail) throws 
AppException {


                String key = sp.getKey();
                FeedURLFactory urlFactory = FeedURLFactory.getDefault();
                URL cellFeedUrl = null;
                try {
                        cellFeedUrl = urlFactory.getCellFeedUrl(key, "od6", 
"private",
                                        "full");
                } catch (MalformedURLException e3) {
                        e3.printStackTrace();
                }

                CellFeed batchRequest = new CellFeed();
                for (CellInfo cellId : cellInfos) {
                        CellEntry batchEntry = new CellEntry(new 
Cell(cellId.getRow(),
                                        cellId.getCol(), 
cellId.getCellValue()));
                        batchEntry.setId(String.format("%s/%s", 
cellFeedUrl.toString(),
                                        cellId.getIdString()));
                        BatchUtils.setBatchId(batchEntry, cellId.getIdString());
                        BatchUtils.setBatchOperationType(batchEntry,
                                        BatchOperationType.QUERY);
                        batchRequest.getEntries().add(batchEntry);
                }

                CellFeed cellFeed = null;
                try {
                        cellFeed = service.getFeed(
                                        
getContentQueryWithQueryParameter(cellFeedUrl,
                                                        "xoauth_requestor_id", 
userEmail), CellFeed.class);
                } catch (IOException e) {
                        String msg = "Error getting feed";
                        throw new AppException(msg, e);
                } catch (ServiceException e) {
                        String msg = "Error getting feed";
                        throw new AppException(msg, e);
                }
                CellFeed queryBatchResponse = null;
                try {
                        queryBatchResponse = service.batch(
                                        new 
URL(cellFeed.getLink(Link.Rel.FEED_BATCH,
                                                        
Link.Type.ATOM).getHref()), batchRequest);
                } catch (BatchInterruptedException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (MalformedURLException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (IOException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (ServiceException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                }

                // NOTE: here we are assuming that the size of cellInfo list is
                // equal to
                // the size of the list which is
                // obtained from queryBatchResponse.getEntries(). This is done 
to
                // insert
                // the value in the cellEntry
                CellFeed batchRequest2 = new CellFeed();
                for (int i = 0; i < queryBatchResponse.getEntries().size(); 
i++) {
                        CellEntry batchEntry = 
queryBatchResponse.getEntries().get(i);
                        
batchEntry.changeInputValueLocal(cellInfos.get(i).getCellValue());
                        BatchUtils.setBatchId(batchEntry, batchEntry.getId());
                        BatchUtils.setBatchOperationType(batchEntry,
                                        BatchOperationType.UPDATE);
                        batchRequest2.getEntries().add(batchEntry);
                }

                // Submit the update
                Link batchLink = cellFeed.getLink(Link.Rel.FEED_BATCH,
Link.Type.ATOM);
                CellFeed batchResponse = null;
                try {
                        batchResponse = service.batch(new 
URL(batchLink.getHref()),
                                        batchRequest2);
                } catch (BatchInterruptedException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (MalformedURLException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (IOException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                } catch (ServiceException e) {
                        String msg = "Batch process interrupted.";
                        throw new AppException(msg, e);
                }

                boolean isSuccess = true;
                for (CellEntry entry : batchResponse.getEntries()) {
                        String batchId = BatchUtils.getBatchId(entry);
                        if (!BatchUtils.isSuccess(entry)) {
                                isSuccess = false;
                                BatchStatus status = 
BatchUtils.getBatchStatus(entry);
                                log.error("Batch process failed for bacth id" + 
batchId
                                                + "due to :" + 
status.getReason() + "having content : "
                                                + status.getContent());
                        }
                }
        }

        private ContentQuery getContentQueryWithQueryParameter(URL feedUrl,
                        String parameterType, String parameterValue) {
                ContentQuery query = new ContentQuery(feedUrl);
                query.addCustomParameter(new 
Query.CustomParameter(parameterType,
                                parameterValue));
                return query;
        }

        I get the following exception :

        
com.metacube.aryabhata.service.googleservice.GoogleSpreadsheetService.insertCells(GoogleSpreadsheetService.java:
330)
        ... 49 more
Caused by: java.io.IOException: Could not fetch URL:
http://spreadsheets.google.com/feeds/cells/0AlDmkoHLzPmGdENBWm12Y2RkVTFfSlkyU0NwMGVjZ1E/od6/private/full?xoauth_requestor_id=admin%40xavierjaipur.org
        at
com.google.appengine.api.urlfetch.URLFetchServiceImpl.convertApplicationException(URLFetchServiceImpl.java:
115)
        at
com.google.appengine.api.urlfetch.URLFetchServiceImpl.fetch(URLFetchServiceImpl.java:
42)



        I believe this has somethng to do woth retrieveing the "http://
spreadsheets.google.com/feeds/cells/" using 2 legged OAuth.
        But i am not able to find out any useful answer..

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to