0

I don't know what the proper name for this sort of programming, but all I am want to do is the following:

Let's say I want to use google translate service so I created an application either (android apps, or some local application that is Java that run on my local machine) and in this application I wanted to type a word and when I hit find, I need my application to go an input the word into google translate and bring me the result to my application.

the google translate is just an example so I want to know the general path that I should use to create such software

Another example to make things clear, for an android App what is the proper name and the proper way to create an app that uses the http://www.flickr.com/ to pick random pictures and display them and when the user hit refresh button another set of new pictures will show up

so you see, in the second example, I am trying to menipulate a website to get some spacific feature from it, instead of displaying the entire website.

I am aware of the copywriter and asking for permission from the owners of the website before doing such thing if this is consider to be illegal.

Thanks

Shakash3obd
  • 13
  • 2
  • 9
  • +1 to using an API. Check [this][1] SO post for a good start. [1]: http://stackoverflow.com/questions/2246017/c-sharp-google-translate – oolong Mar 11 '12 at 08:29
  • Thank, but I guess I choose the wrong example here by picking google which apparently has an API for its services. But my question was the generalization form of taking advantages of websites services. What about if a website that does not have an API, do I need to make my app like a browser and pars every request? – Shakash3obd Mar 11 '12 at 08:57

2 Answers2

0

you should use the api services of the websites you are thinking to use. for example for google translate, (although you can make this by creating intent locally)you should make a url call to the api service of google translate and parse the coming json result(there is probably libraries for parsing). then according to the result you shoudl update your ui. on appropriate user actions, such as button clicks or text inputs, you can retrieve and show data following this pattern. you can later improve the usage by caching the data etc.

Behlül
  • 3,412
  • 2
  • 29
  • 46
  • From what I understood from you, Does that mean that for every website there should be an API that programmer can use? – Shakash3obd Mar 11 '12 at 08:47
  • not all websites have an api. but if the website allows programmers to use its data, yes it should have an api. and i don't think fetching real time information from a website without an api is a good idea(big overhead plus html source code may change) – Behlül Mar 11 '12 at 08:49
0

I understand that you need to connect to a website, download the webpage (the html file) and process it, in order to show the user the results of this processing. I think that you can use two different classes: - HttpURLConnection: it's included in java.net. He goes a link with an example: http://www.androidsnippets.com/http-requests-with-java-api-urlconnection - HttpGet and HttpPost: included in Android. A link with an example: http://w3mentor.com/learn/java/android-development/android-http-services/example-of-http-get-request-using-httpclient-in-android/

Which one to use? I'm afraid it depends on your project. With HttpURLConnection you can have more control over the http commands (i. e. you can send a HEAD command).

BWitched
  • 484
  • 4
  • 6