Official Google Spreadsheet/Drive usage - java

The Google SpreadsheetService seems a 'work in progress' with sometimes/suddenly slow answers, random error messages etc. As some people already suggest i'm using the Google Drive API where possible when working with the Spreadsheet API. But i couldn't find decent documentation about the Google Drive/Spreadsheet API mix.
With some debugging and trial/error i created an 'entrypoint' at the level of SpreadsheetEntry:
String lSpreadsheetFileId = pSpreadsheetFile.getId();
String lSpreadsheetUrlString = String.format("https://spreadsheets.google.com/feeds/spreadsheets/%s", lSpreadsheetFileId);
URL lSpreadsheetUrl = new URL(lSpreadsheetUrlString);
SpreadsheetEntry lSpreadsheetEntry = mSpreadsheetService.getEntry(lSpreadsheetUrl, SpreadsheetEntry.class);
Now i can start with a query on the SpreadsheetService or with a Google Drive File. Both deliver a SpreadsheetEntry. From this point the code is equal for both situations.
This works, but is is my own Google hacking solution which could break with an update on the interface. I saw some posts with more 'official' methods:
urlFactory.getWorksheetFeedUrl(file.getId(), "private", "full"); // (or any other feed url builder). file.getId()
What is the official 'by design' way to use Google Drive files with Google Spreadsheet?
Can i get some real code examples (more than; "just use the feed" etc.)?

Google Spreadsheet Service is already deprecated. Use Google Apps Script API instead on your implementation on integrating Google Drive and Spreadsheet. Using the Apps Script API, you can almost implement most of the Google Apps integration in your application.

If you really need a SpreadsheetEntry, you have to sift through the SpreadsheetFeed and look for the key. You can implement a title query to reduce the number of spreadsheets to examine:
SpreadsheetQuery spreadsheetQuery
= new SpreadsheetQuery(urlFactory.getSpreadsheetsFeedUrl());
spreadsheetQuery.setTitleQuery(spreadsheet);
SpreadsheetFeed spreadsheetFeed = myService.query(spreadsheetQuery, SpreadsheetFeed.class);
There doesn't seem to be a query for the key.
However, there is hardly a functionality that requires a SpreadsheetEntry and cannot be done with Drive API or lower level feeds (Worksheed, List, or CellFeed)

Related

Android autofill service save request on sensitive data

I'm trying to give the user the option to save their passwords after registering on a website, using the autofill service provided by android.
List<FillContext> contexts = request.getFillContexts();
AssistStructure structure = contexts.get(contexts.size() - 1).getStructure();
ParsedStructure parsedStructure = ParsedStructure.parse(structure);
parsedStructure.getPasswordView().getText().toString()
This code is in the onSaveRequest method of Android's AutofillService.
When I log the last line, the text in the console only contains asterix characters and not the password itself. Does anyone have an idea why that is and an solution for that?
AS most of the browsers are in Compatibility mode and do not support the native autofill api yet.
Read more at the android documentation.

How to retrieve from Azure mobile services using android studio

I am new to Android and Windows Azure. I have successfully inserted data from Android application but how do I retrieve single data and post that data on a TextView?
The read function after the gettable class is also not working. What is the exact function use for it? I have followed these instructions but they did not work for me, also I do not understand the documentation.
Currently, I just can provide some tutorials about how to use query data from azure database. I recommend you can refer to this official document about how to use Azure Client Library using Java: https://azure.microsoft.com/en-us/documentation/articles/mobile-services-android-how-to-use-client-library . You can focus on two part: “how to query data from a mobile service” and “how to bind data to the UI”.
At the same time, you can view this video from Channel 9: https://channel9.msdn.com/Series/Windows-Azure-Mobile-Services/Android-Getting-Started-With-Data-Connecting-your-app-to-Windows-Azure-Mobile-Services.
The sample code project of this tutorial, please go to the GitHub link https://github.com/Azure/mobile-services-samples/tree/master/GettingStartedWithData .
For the ‘getTable(Class )’ function is not working, please double check whether the class name is same as table name. If they are same, you can use it like below:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable(ToDoItem.class);
If not, you can write you code like this:
MobileServiceTable<ToDoItem> mToDoTable = mClient.getTable("ToDoItemBackup", ToDoItem.class);
For further better support, please share more detail about your code snippet .

Java Program and YouTube API

I'm trying to write a program that checks if a user uploaded a new video. I wanted to make it a backend job that constantly checks a users most recent video and then send a push my users utilizing my application. Is there any documentation or sample code on this matter? I haven't the slightest clue where to start.
The simplest way I found is via RSS feed. Simple to parse. Simple to get it going. Begin checking this out:
https://www.youtube.com/t/rss_feeds
To PARSE the RSS in java, use Rome: https://github.com/rometools/rome
Download YouTube's Java API and then use the code they provide:
String feedUrl = "http://gdata.youtube.com/feeds/api/users/GoogleDevelopers/uploads";
VideoFeed videoFeed = service.getFeed(new URL(feedUrl), VideoFeed.class);
printVideoFeed(videoFeed, true);
This is for version 3, which is the latest they provide.

how can i get place marker in google map api v3?

i was using google map apis v2 in my project. Now i want to change google map api version to v3. In the old code i was parsing the json string in the following way
JSONObject placemark = json.getJSONArray("Placemark").getJSONObject(0);
AddressDetail address = new AddressDetail();
address.setFullAddress(placemark.getString("address"));
JSONObject area = placemark.getJSONObject("AddressDetails").getJSONObject("Country").getJSONObject("AdministrativeArea");
address.setCounty(area.getString("AdministrativeAreaName"));
JSONObject subArea = area.getJSONObject("SubAdministrativeArea");
address.setTown(subArea.getString("SubAdministrativeAreaName"));
JSONObject locality = subArea.getJSONObject("Locality");
address.setLocalityName(locality.getString("LocalityName"));
address.setPostCode(locality.getJSONObject("PostalCode").getString("PostalCodeNumber"));
address.setStreet(locality.getJSONObject("Thoroughfare").getString("ThoroughfareName"));
but when i change Google map version to v3 and generate url to
http://maps.google.com/maps/api/geocode/json?sensor=false&latlng=51.520205,-0.1379954
and send request to server.Getting json having no placemark in it.
how can i get placemark in google map api v3?
The structure of the response changed in V3 of the geocoding web service. You'll need to modify your code to remap to the new structure. Though it's not that hard.
For example, FullAddress in your code is based on formatted_address and Street = route. And so on. You can see the full list of elements here:
http://code.google.com/apis/maps/documentation/geocoding/#Types
Have a look at the code in the Google Maps API v3 Geocoder Tool, it probably has what you need.
One thing though: generating requests directly to the API at http://maps.google.com/maps/api/geocode/json is not the right thing to do in JavaScript. It happens to work because the API is in the same domain, but you should never do that. Instead, you should always use the Geocoding Service that is part of the Maps JavaScript V3 API.
Using this service you don't actually need to parse the JSON response at all, the API will do it for you and then you'll have an array of Geocoding Results. There, results[0] would replace json.getJSONArray("Placemark").getJSONObject(0);
To see how you'd translate your whole address extraction code, look at the source code for the above geocoder tool. Instead of an object tree, V3 gives you a flat array (address_component). Each component has a short_name, a long_name and an array (types) of Address Component Types. These types are what tells you how the components relate to each other.
Also, you should never assume that there will always be a component of any given type. Your current code relies blindly on the presence of a locality in the response, but that will not always be the case.

XEP-0080 User Location in Smack Library

I would like to create a simple XMPP client in java that shares his location (XEP-0080) with other clients.
I already know I can use the smack library for XMPP and that it supports PEP, which is needed for XEP-0080.
Does anyone have an example how to implement this or any pointers, i don't find anything using google.
thanks in advance.
Kristof's right, the doc's are sparse - but they are getting better. There is a good, albeit hard to find, set of docs on extensions though. The PubSub one is at http://www.igniterealtime.org/fisheye/browse/~raw,r=11613/svn-org/smack/trunk/documentation/extensions/pubsub.html.
After going the from scratch custom IQ Provider route with an extension I found it was easier to do it using the managers as much as possible. The developers that wrote the managers have abstracted away a lot of the pain points.
Example (modified-for-geoloc version of one rcollier wrote on the Smack forum):
ConfigureForm form = new ConfigureForm(FormType.submit);
form.setPersistentItems(false);
form.setDeliverPayloads(true);
form.setAccessModel(AccessModel.open);
PubSubManager manager
= new PubSubManager(connection, "pubsub.communitivity.com");
Node myNode = manager.createNode("http://jabber.org/protocol/geoloc", form);
StringBuilder body = new StringBuilder(); //ws for readability
body.append("<geoloc xmlns='http://jabber.org/protocol/geoloc' xml:lang='en'>");
body.append(" <country>Italy</country>");
body.append(" <lat>45.44</lat>");
body.append(" <locality>Venice</locality>");
body.append(" <lon>12.33</lon>");
body.append(" <accuracy>20</accuracy>");
body.append("</geoloc>");
SimplePayload payload = new SimplePayload(
"geoloc",
"http://jabber.org/protocol/geoloc",
body.toString());
String itemId = "zz234";
Item<SimplePayload> item = new Item<SimplePayload>(itemId, payload);
// Required to recieve the events being published
myNode.addItemEventListener(myEventHandler);
// Publish item
myNode.publish(item);
Or at least that's the hard way :). Just remembered there's a PEPManager now...
PEPProvider pepProvider = new PEPProvider();
pepProvider.registerPEPParserExtension(
"http://jabber.org/protocol/tune", new TuneProvider());
ProviderManager.getInstance().addExtensionProvider(
"event",
"http://jabber.org/protocol/pubsub#event", pepProvider);
Tune tune = new Tune("jeff", "1", "CD", "My Title", "My Track");
pepManager.publish(tune);
You'd need to write the GeoLocProvider and GeoLoc classes.
I covered a pure PEP based approach as an alternative method in detail for Android here: https://stackoverflow.com/a/26719158/406920.
This will be very close to what you'd need to do with regular Smack.
Take a look at the existing code for implementations of other extensions. This will be your best example of how to develop with the current library. Unfortunately, there is no developers guide that I know of, so I just poked around to understand some of the basics myself until I felt comfortable with the environment. Hint: Use the providers extension facility to add custom providers for the extension specific stanzas.
You can ask questions on the developer forum for Smack, and contribute your code back to the project from here as well. If you produce an implementation of this extension, then you could potentially get commit privileges yourself if you want it.

Categories

Resources