How to use online API in java web Application - java

I am working on my college final year project and ive been developing a project in which ive to use any text to speech online api. My project is servlet and jsp based web application but i dont know how to use the API in my code. Can any one help me.
I have seen a free TTS Api such as http://www.voicerss.org/api/documentation.aspx.

Using Fluent HC:
String key = "..."; // your API key
byte[] mp3speech = Request.Get("http://api.voicerss.org/?key=" + key + "&hl=en-us&src=I+am+very+lazy+student.").execute().returnContent().asBytes();
// do anything you need with the result

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.

Official Google Spreadsheet/Drive usage

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)

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.

vaadin javascript

I am trying to integrate some js project into my vaadin app. And I tried the methods to invoke external javascript code, only successed on some easy/javascript.
I tried the NativeJs lib
and the code is:
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript("alert('foo');");
nativeJScomponent.execute();
addComponent(nativeJScomponent);
However, when I used some other code like:
String jsCode = "<div /><script type=\"text/javascript\">var d = new Date();"
+ "var time = d.getHours();"
+ "if (time < 10) {document.write(\"<b>Good morning</b>\");}</script>";
NativeJS nativeJScomponent = new NativeJS();
nativeJScomponent.setJavascript(jsCode);
nativeJScomponent.execute();
addComponent(nativeJScomponent);
It failed to display content.
And I also used the customelayout and label to run javascript. The same results came.
Is there any method to integrate vaadin with js?
Window window = new Window("");
window.executeJavascript("javascript:testFunctionCall();");
The correct way to do this is to implement AbstractJavaScriptComponent. This allows you to include a plain Javascript file in your project and control that library from the server side through RPC calls and shared state.
An easy tutorial can be found here and the Book of Vaadin goes more in-depth here. You can also take a look at the source code of my Vaadin addon which integrates a Javascript media library with Vaadin.
have you looked and tried to run the source in http://uilder.virtuallypreinstalled.com/run/Calling_External_JavaScript/

How do I write Facebook apps in Java?

I have looked in vain for a good example or starting point to write a java based facebook application... I was hoping that someone here would know of one. As well, I hear that facebook will no longer support their java API is this true and if yes does that mean that we should no longer use java to write facebook apps??
There's a community project which is intended to keep the Facebook Java API up to date, using the old official Facebook code as a starting point.
You can find it here along with a Getting Started guide and a few bits of sample code.
Facebook stopped supporting the official Java API on 5 May 2008 according to their developer wiki.
In no way does that mean you shouldn't use Java any more to write FB apps. There are several alternative Java approaches outlined on the wiki.
You might also want to check this project out; however, it only came out a few days ago so YMMV.
I write an example using facebook java api
It use FacebookXmlRestClient in order to make client request and print
all user infos
http://programmaremobile.blogspot.com/2009/01/facebook-java-apieng.html
BatchFB provides a modern Java API that lets you easily optimize your Facebook calls down to a minimum set:
http://code.google.com/p/batchfb/
Here's the example taken from the main page of what you can effectively do in a single FB request:
/** You write your own Jackson user mapping for the pieces you care about */
public class User {
long uid;
#JsonProperty("first_name") String firstName;
String pic_square;
String timezone;
}
Batcher batcher = new FacebookBatcher(accessToken);
Later<User> me = batcher.graph("me", User.class);
Later<User> mark = batcher.graph("markzuckerberg", User.class);
Later<List<User>> myFriends = batcher.query(
"SELECT uid, first_name, pic_square FROM user WHERE uid IN" +
"(SELECT uid2 FROM friend WHERE uid1 = " + myId + ")", User.class);
Later<User> bob = batcher.queryFirst("SELECT timezone FROM user WHERE uid = " + bobsId, User.class);
PagedLater<Post> feed = batcher.paged("me/feed", Post.class);
// No calls to Facebook have been made yet. The following get() will execute the
// whole batch as a single Facebook call.
String timezone = bob.get().timezone;
// You can just get simple values forcing immediate execution of the batch at any time.
User ivan = batcher.graph("ivan", User.class).get();
You might want to try Spring Social. It might be limited in terms of Facebook features, but lets you also connect to Twitter, LinkedIn, TripIt, GitHub, and Gowalla.
The other side of things is that as Facebook adds features some of the old API's might break, so using a simpler pure FB api (that you can update when things don't work) might be a good idea.
This tutorial will literally step you through everything you need to do: http://ocpsoft.org/opensource/creating-a-facebook-app-setup-and-tool-installation/
It comes in 3 parts. The other 2 are linked from there.

Categories

Resources