Manipulating single cell in a google spreadsheet - java

So for an application that I am writing for a friend of mine, I needed to interact with the google drive and google data api in order to create folders and manipulate data in a google spreadsheet.
Now looking at the API beforehand it all seemed pretty straightforward.
Until you actually make a start and figure out that every piece of documentation you could possibly find on the internet is pretty much deprecated.
Eventually I figured out most parts after some time on the internet (Like authentication and creating new folders / copying files etc.)
so far so good.
But now I have come at the following problem:
I am trying to manipulate a single cell (Well actually multiple but 1 by 1) and after 2 days of going through google's atrocious documentation I have turned to you guys.
I have come as far as authenticating my user and even reading the values from the spreadsheet however I can't seem to write to it.
CellEntry newEntry = new CellEntry(row,col, "value");
service.insert(cellFeedUrl, newEntry);
System.out.println("Added!");
This is what I got from their code sample, however the service.insert() returns an error
Exception in thread "main" com.google.gdata.util.ServiceException: Internal Server Error
Internal Error
at com.google.gdata.client.http.HttpGDataRequest.handleErrorResponse(HttpGDataRequest.java:632)
at com.google.gdata.client.http.GoogleGDataRequest.handleErrorResponse(GoogleGDataRequest.java:564)
at com.google.gdata.client.http.HttpGDataRequest.checkResponse(HttpGDataRequest.java:560)
at com.google.gdata.client.http.HttpGDataRequest.execute(HttpGDataRequest.java:538)
at com.google.gdata.client.http.GoogleGDataRequest.execute(GoogleGDataRequest.java:536)
at com.google.gdata.client.Service.insert(Service.java:1409)
at com.google.gdata.client.GoogleService.insert(GoogleService.java:613)
I really hope someone here can help me out, I am pretty desperate and google has not been my friend on this one (Neither has google's own documentation)
A.E.

I figured it out myself,
As I already said in one of the comments I passed a value of 0 to variable col, passing that to the google server gave me an error back.
Changing the loop that was calling:
new CellEntry(row,col, "value");
To start at 1 instead of 0 fixed it.
AE

Related

JAVA EWS: setExtendedProperty with MapiPropertyType.Binary

I have to enhance an existing JAVA app to store deadlines into several calendar all owned (created) by the same Shared-Mailbox.
Synchronisation of the deadlines in the app and the outlook calendars is no problem.
Apart from syncing the dates the JAVA app should be able to send invitations to the specific calendar. I have used the description https://willcode4foodblog.wordpress.com/2012/04/13/understanding-sharing-invitation-requests-ews-managed-api-1-2-part-1/. I needed to port that stuff from c# to JAVA. On sendAndSaveMessage I always receive this Exception:
exchange.webservices.data.core.exception.service.remote.ServiceRequestException: The request failed. An internal server error occurred. The operation failed.
at microsoft.exchange.webservices.data.core.request.SimpleServiceRequestBase.internalExecute(SimpleServiceRequestBase.java:74)
at microsoft.exchange.webservices.data.core.request.MultiResponseServiceRequest.execute(MultiResponseServiceRequest.java:158)
at microsoft.exchange.webservices.data.core.ExchangeService.sendItem(ExchangeService.java:789)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.internalSend(EmailMessage.java:156)
at microsoft.exchange.webservices.data.core.service.item.EmailMessage.sendAndSaveCopy(EmailMessage.java:300)
Using the debugger I found out, that all Extended Properties of MapiPropertyType.Binare have a null value. That's eg.
byte[] binInitiatorEntryId = hexStringToByteArray(initiatorEntryID);
ExtendedPropertyDefinition pidLidSharingInitiatorEntryId =
new ExtendedPropertyDefinition(propertySetSharing, 0x8A09, MapiPropertyType.Binary);
invitationRequest.setExtendedProperty(pidLidSharingInitiatorEntryId, binInitiatorEntryId);
So in the debugger the extended property exists, but the value is "null".
All other fields that are noted in the example look ok in the debugger. It's just that the binaries are all "null". I also compared the sharing_metadata.xml attachment with one created by Outlook and they are identical. Ok, there are a few fields I got to play with (let's say: do I have to use a "special folder" for pidLidSharingFlavor because I didn't find any explanations in the specs on what is a special folder). But since it is obvious that a "null" value for MapiPropertyType.Binary is not correct it does not make any sense to check other possibilities.
So mainly there are two questions regarding this issue which I hope someone with a bit more experience could explain:
Question 1: Is there any special way in JAVA to store Extended Properties of MapiPropertyType.Binary?
Question 2: Is there any way to get more information on the "internal server error occured" from EWS? Even enhancing the trace does not give any more information beside the XML representation of the message.
Thanks in advance.
ChriS

Reading a lot of data from the internet

I am currently working on a project for my portfolio. I having a little trouble trying to find the right solution to this problem mainly because I have never tried it before.
I am using a free API service that I found online. I have created the database to match all the information, and not I just need to download the information and parse into my application.
I have parsed data from the API (JSON) and into my database. A couple of suggestions that I have found is reading 10 records at a time, but I want to try reading everything at once and then updating accordingly (let us say every 24 hours).
The APi I am using is the a free Game of Thrones API and below is the list I want of about the URL is formed to access each part data as I move through it.
https://anapioficeandfire.com/api/characters/
https://anapioficeandfire.com/api/books/
https://anapioficeandfire.com/api/houses/
At the end of the each of these URLS is a number that indicates the record number that I am trying to get. I have done this before while get information from a single page, and the page contained multiple JSON object. This time I need to move through multiple pages to get the single object on that page.
To give you an idea of the steps that I am looking for :
Go the page
Download the Information
Move on the next page
Break when there when I have reached the end.

Java: How can I assemble/create a single instance for classification using a Weka generated model?

I've been searching for an answer to this for a while to no avail.
First a bit of background: I'm trying to create an AI for robocode using Weka.
I'm first logging the required data from a manual robot to an ARFF file, this is working as it should.
This data is then processed this using Weka and a model created, I'm then saving this file.
I can successfully import the model and classify a dataset that has been imported from another arff file and use the results.
What I want to do now is every time the game status changes is assemble an instance and classify it, to decide for example which way to move etc. using my previously saved model.
I've tried to look it up on the wiki: http://weka.wikispaces.com/Programmatic+Use
and this ibm tutorial: http://www.ibm.com/developerworks/opensource/library/os-weka3/ to name a couple, I've also been looking through the APIs but that hasn't given me much to go on.
Much of what I've tried is deprecated, for example creating a prototype with the attributes and fast vectors then creating an empty dataset. Then creating a new instance with the required values using somthing like inst.setvalue(attrib, value) and adding it to the dataset.
Also what about the class index, or the attribute I'm predicting, in the instance does it have to be null or set to missing or something, as surley I won't know that value as I'm trying to predict it?
So are there any ideas how I can go about this?
any help is greatly appreciated,
Thank you muchly.
Managed to find the answer a while ago.
For anyone else having trouble with this basically what you have to do is in the Weka manual included with every download, (its a pdf).
Page 202 onwards in the manual - Section 16.3 "Creating datasets in memory".
Follow the steps there and it works perfectly.

What does flash.discard do? What's the difference from flash.clear()?

I haven't found any documentation on flash.discard(). What does it do?
After looking at the code, this is what I understand:
The Flash data is ultimately for storing data between requests.
Since Play is stateless, that state is saved in a session cookie, which is send to the client and send back with the next request.
The data Map is the data that comes from the client via the cookie.
The out Map is the data that the Play app writes to the Flash instance.
If the data changed, the data in the out Map is used to build the content of the cookie to send back to the client.
So from this, I would say, that flash.discard() is used to throw away everything that would go to the client, and flash.clear() is used to throw away everything that came from the client...
That's a good question. While I don't know the answer either, the source code at github should help:
https://github.com/playframework/play/blob/master/framework/src/play/mvc/Scope.java
A quick glance shows the Scope keeps two hashmaps, one named data and other named out.
They both store the same information. But the flash.clear() is acting upon data and flash.discard() is acting upon out... Funny...
Better call both, just in case =)

Get the content of the HTTP stream in Java + Mozilla XPCOM

I've often read StackOverflow as a source to get answers; but now I have a very specific question and I can't really find any data on the internet. I trust you to be as helpful as always! :D
Basically, I'm relying on Mozilla's XULRunner and its XPCOM objects to analyze the HTTP stream of an SWT browser in a Java application on Linux.
Heavily based on Snippet128 and Snippet321 from the Java SWT website (can't post more than 1 URL sorry :/ ), my browser so far can parse all of the HTTP headers using an nsIHttpHeaderVisitor - and do some pretty stuff like printing them on a tree and such.
Full source is here.
Now... That's already pretty good. It covers the majority of what I want to do (school assignment at first, going a bit further than asked!).
But what I would really like is to be able to get the raw "content" data from every HTTP request: HTML of course ; but also CSS and images.
I've been trying different ways to achieve this goal, but everything failed so far:
Using an XPCOM object - which one?
nsIInputStream would be a good one. But I can't seem to find where the good stream actually is... The nsIHttpChannel open() method (who gives back an nsIInputStream) seems to be called by the SWT browser, leaving me with no way of getting the stream back.
nsIRequest : no luck.
another Listener that I'd have missed? I just spent an hour trying to use the nsIHttpActivityObserver interface, but it doesn't give me any HTTP content (merely GETs and 200 OK).
Using another object
the SWT's browser for instance. Well it kinda works: its getText() method gives me the html source of the page I'm visiting. But I want more!
I'm really stuck here, and I would greatly appreciate any help.
Cheers!
Florent
Perhaps nsITraceableChannel can help you?

Categories