How to get the Google's search result using Java - java

According to the answer in here, using Gson we can programmatically achieve to retrieve the result that Google will return to a query. Nonetheless, yet there are 2 questions are remaining in my mind:
How can we do similar thing for Bing?
How can we get more than 4 results based on the referred answer? Because the results.getResponseData().getResults().get(n).getUrl() for n>4 returns exception.

As #Niklas noted, google search api is deprecated, thus you should not use it for your project. Currently the only solution would be to get search result by http request to get a html search results and than parse it yourself.
In case of Bing, there is a search API, but it has a limited number of calls for free users. If you need to make a lot of requests, than you will have to pay for it. https://datamarket.azure.com/dataset/5BA839F1-12CE-4CCE-BF57-A49D98D29A44

Related

String Translation from API call

I have a found a free API to get some data I need for my app. The thing is the values that I get are in English.
I wanted to know if there is some way to translate this strings in my language before showing them to the users.
You can translate text but it will require another API call. Not only that, but you will have to create an appropriate request object and parse a response object from your chosen API.
You have various API providers to choose from, the top Google hits being:
Google: https://cloud.google.com/translate/
Yandex: https://tech.yandex.com/translate/
But beware! Machine translation is patchy at best. The likelihood of getting odd sounding or outright wrong results, particularly for anything other than simple text, is very high.

how to input large amounts of data into a query parameter via REST Assured

I have an API that returns a list of ~30,000 SKUs. I then need to insert each SKU into the query parameter URL of another API to validate the response of this second API.
I know that something like this is possible with Jmeter where you could possibly do this via a CSV file. How can I accomplish this via REST Assured? An example/sample would be greatly appreciated!
Similar question also applies to using outputs from an API to use as input in body content...
Thanks.
Short answer.You can't as it comes to query parameters. You can have no more than 2000 characters in your URL. Explanation here : What is the maximum length of a URL in different browsers?
With respect of POST method you don't have constraints.
If you are open to evaluating alternatives to REST-assured, Karate allows you to easily achieve such a data-driven test and it is based on Cucumber as well.
Disclaimer: I am the dev.
In the demos you will find a number of examples that use dynamic JSON data to drive a loop making an HTTP call. Yes, you can dynamically use the data in HTTP responses also in future steps.

Get notification in my client code

I want to get the notifications about any change in any issues in my jira server.
I have basic code for connecting jira from java code using jira-rest-java-client library that they have provided.
I searched their javadocs and also went through some classes in that API library but I could not find any methods/classes which would be helpful to me.
Does anyone know if it is possible to get notification events from changes in jira to my java code (may be via polling or something like that).
What do you want to achieve?
You want to have push notifications? There isn't any, IMHO.
UPDATE: However, there is this WebHook thingy: https://confluence.atlassian.com/display/JIRA/Managing+Webhooks.
I have no expertise with it, but it is promising, please read this short introduction also: http://blogs.atlassian.com/2012/10/jira-5-2-remote-integration-webhooks/.
You are looking for something that gives you back what changed in the last N minutes, something like the Activity Stream? You can get the RSS feed of Activity Streams for Projects and for Users.
How
The base URL is https://jira.contoso.com/activity. Then you can append querystring parameters, like maxResults for paginating.
Selecting the data source is through the filters you provide in the streams parameter. It looks like it is JQL, but it's not.
Examples:
List a project's activites: ?streams=key+IS+SOMEPROJ.
List a user's activites: ?streams=user+IS+foobar.
List event between two dates: ?streams=update-date+BETWEEN+1425300236000+1425300264999. (Note: the epoch is the millisecond precision epoch.)
List user activities in one project: ?streams=user+IS+JohnDoe&streams=key+IS+PROJECTKEY.
More complex ones: ?streams=user+IS+JohnDoe&streams=key+IS+PROJECTKEY&streams=activity+IS+issue:close
Watch out, it is case sensitive, on my JIRA 6.1.9, if I write Is instead of IS, I get an error page (but not if AFTER is not all uppercase o.O).
Also note, that spaces should be encoded as plus signs (+), not URL encoded (%20 for spaces).
If you go to your JIRA, and fetch the following URL: https://jira.yourserver.com/rest/activity-stream/1.0/config, it will list all the combinations it accepts.
What
The call returns a standard Atom feed. You can then process it with XML query tools, or with other Java-based RSS/ATOM reader libraries.
Noteworthy document about this topic: https://developer.atlassian.com/docs/atlassian-platform-common-components/activity-streams/consuming-an-activity-streams-feed

How to get multiple users timeline efficiently using twitter4j?

I want to get time line data for 2 users. Currently I am calling getUserTimeline("username",paging) method for both the users and combining the data. Is there any optimal way of doing it, for example, using one twitter api call or is this the only way it can be done? Please help.
As far as I know Twitter APIs does not allow to query for multiple users' timelines.
I guess you already did it, but you should double check that I am not wrong by looking at the official Twitter APIs documentation.

Receive JSON list from http://www.autorenlexikon.lu

I want to read a JSON list from a webservice with Java. The webservice returns a list of authors from luxemburg, e.g. sorted by the year. That's the web-site:
http://www.autorenlexikon.lu/page/periods/1919-1945/1/1/DEU/index.html
So far, I know that I can receive a JSON document with a request like this:
http://www.autorenlexikon.lu/mmp/json.document_list/DEU/0?search_since=1919&search_until=1945
But I only get the first 20 entries. How can I get the next 20 entries? I think the solution is in the JavaScript-code of the web-site, but I am pretty new in JavaScript (also in JSON).
EDIT:
There isn't any official API.
I have already tried:
http://www.autorenlexikon.lu/mmp/json.document_list/DEU/0?pageSize=1000&search_since=1919&search_until=1945
http://www.autorenlexikon.lu/mmp/json.document_list/DEU/0?page_Size=1000&search_since=1919&search_until=1945
...and many more. Who does the JavaScript-code receive all entries? Couldn't I copy this mechanism?
You should check their API and look for a parameter that let's you define the page or the range of results you want to get.
Edit Seems like you'd have to make a POST request and add the start index as well as the page size as post parameters. For more information see #matthijs koevoets' answer.
It depends on how the Webservice has been coded. Nothing to do with JSON specifically. From the results you can see it says
"pageSize":20,
You just have to figure out how to call the Web service with a page size. It may not allow you to query it with a different page size. That's up to the Web service API coded by their developers
their service seems to accept POST parameters only: sort=year&dir=asc&startIndex=0&results=100

Categories

Resources