Twitter4j API track and location filter - java

I'am using Twitter4j API to collect tweets from india. I am applying filter to collect tweets having specific keywords only, but i'am getting all tweets from india region, not having that specific keywords. my code is
FilterQuery filter = new FilterQuery();
String keyword[]= {"flu"};
double [][]location ={{68.1,8.06},{97.41,37.10}};
filter.track(keyword);
filter.locations(location);
twitterstream.addListener(listener);
twitterstream.filter(filter);
how can get tweets from India having "flu" as a part of tweet text.

This is so because twitter filter parameters together do not apply as AND but OR.
Check more here - https://dev.twitter.com/streaming/overview/request-parameters
The twitter API documentation also says so -
Bounding boxes do not act as filters for other filter parameters. For example track=twitter&locations=-122.75,36.8,-121.75,37.8 would match any tweets containing the term Twitter (even non-geo tweets) OR coming from the San Francisco area.
Hope this helps.

Related

Accessing google spreadsheet api to fetch data with filter

I am trying to fetch data with specific name from a google spreadsheet using java. I am able to fetch complete data from a column using google api. I specify range as "sheet1!B:B" for example. However, I am not understanding
How to fetch data from multiple columns. How should I pass the range?
How do I specify the data filter for columns.
Any guidance would be really appreciated. I am unable to find it in github or googlespreadsheet api docs. Please help me out
Currently I have code to fetch all values from googlespread sheet using below code
String spreadsheetId="spreadseet id";
String range="Sheet!A2:zz";
Sheets service = new Sheets.Builder(httpTransport, JSON_FACTORY, credential).setApplicationName(APPLICATION_NAME).build();
Sheets.Spreadsheets.Values.Get request=service.spreadsheets().values().get(spreadsheetId, range);
ValueRange response = request.execute();
Let's take the official example provided by google here:
How to fetch data from multiple columns. How should I pass the range?
This is the range:
String range = "Class Data!A2:F";
Which means fetch all the data from the cell A2 to the column F of the sheet with the name Class Data.
How do I specify the data filter for columns.
Once you have all the data you can filter it in a normal for-loop. For example if we want only the column 1 and 2:
List<List<Object>> values = request.execute().getValues();
System.out.println("Name, Gender");
for (List row : values) {
System.out.println(row.get(0)+", "+row.get(1));
}
The output will be:
Name, Gender
Alexandra, Female
Andrew, Male
Anna, Female
More info on the official Java Quickstart.
You can try using RestedBox to access your Google Sheets and local spreadsheet data through an API, including querying. I've been using it for some POC's instead of a database.

How to apply java based filter with JPA pagination?

Input request -
{
Page size = 20
page = 1
withIn distance 20 km;
}
Below is the JPA implemented method.
List<Hotels> hotels = findsByHotelAddress(Address address, Pageable pageable);
let say, After a search, we got 20 hotels on the first page.
Now, after applying the distance filter, we got five users on the first page(1st request) and, four users on the second page(2nd request) and, six users on the third page(3rd request).
I want to know better approach if I want to display all the fifteen filtered hotels only on the 1st page.
FYI: Distance is calculated(using google map) based on user location and Hotel location.
The Distance field is not available in the DB column.
You can try to implement Specification interface . Check it out for more details
Specification-Properties

Username contain Specific word in Twitter API Using Java

How can I search for a word in twitter's users?
for example how can I find all users who has in their names or usernames the word "James"?
If I use twitter.showUser(username) it will return a single user IF IT EXISTS!
I want all the users who may contain username in their usernames or names. I'm using Twitter4J in my application.
Probably the way to go:
Get a list of all available users (http://twitter4j.org/oldjavadocs/4.0.0/twitter4j/api/UsersResources.html#searchUsers-java.lang.String-int-)
Iterate data.stream().anyMatch(x -> x.name.contains('James')).collect(toList)

Get WOEID in Android

I'm developing an app and one of the features I want to include is being able to get the users location and convert it to a WOEID value and then get the weather data from the Yahoo Weather RSS feed. Here's the documentation that states the requirement for the WOEID value:
http://developer.yahoo.com/weather/
You can get the WOEID by using the Yahoo! PlaceFinder API. First you need to request an API key, then you can send your request like this:
http://where.yahooapis.com/geocode?q=[search query]&appid=[yourappidhere]
You will get this as a response:
<ResultSet xmlns:ns1="http://www.yahooapis.com/v1/base.rng" version="2.0" xml:lang="en-US">
<Error>0</Error>
<ErrorMessage>No error</ErrorMessage>
<Locale>en-US</Locale>
<Found>1</Found>
<Quality>85</Quality>
<Result>
<quality>85</quality>
<latitude>38.898708</latitude>
<longitude>-77.036369</longitude>
<offsetlat>38.89719</offsetlat>
<offsetlon>-77.036537</offsetlon>
<radius>400</radius>
<name/>
<line1>1600 Pennsylvania Ave NW</line1>
<line2>Washington, DC 20500-0005</line2>
<line3/>
<line4>United States</line4>
<house>1600</house>
<street>Pennsylvania Ave NW</street>
<xstreet/>
<unittype/>
<unit/>
<postal>20500-0005</postal>
<neighborhood/>
<city>Washington</city>
<county>District of Columbia</county>
<state>District of Columbia</state>
<country>United States</country>
<countrycode>US</countrycode>
<statecode>DC</statecode>
<countycode>DC</countycode>
<uzip>20500</uzip>
<hash>4216F67AA1A143E9</hash>
<woeid>12766118</woeid> // This is what you need
<woetype>11</woetype>
</Result>
</ResultSet>
You can parse the response for the <woeid> tag.
Edit:
If you have an EditText and you want to get the weather based on the city you get from his input then you'll have to do this:
String searchQuery = Uri.encode(myEditText.getText().toString());
Now you'll have your search query. So e.g if the user types in:
Hamburg Germany
then this will convert it to:
Hamburg_Germany

Google Directions API and Using maps.google.com give different Response

Here - > https://maps.google.com/
I queried for parameters
A : antim chauraha, Indore, Madhya Pradesh, India
B : India Collection, Indore, Madhya Pradesh, India
And using the webservice to get as XML, same response from Direction API
http://maps.googleapis.com/maps/api/directions/xml?origin=ANTIM%20CHAURAHA,Indore,Madhya%20Pradesh,India&destination=INDIA%20COLLECTION,PALSIKAR,Indore,Madhya%20Pradesh,India&sensor=false
Those responses do not match at all. You see the distance, direction or anything.
Am I doing something wrong?
Google Maps uses additional information to locate your "query string". The directions API uses postal addresses (for the most part).
Neither of these looks like a particularly good "address"
A : antim chauraha, Indore, Madhya Pradesh, India
B : India Collection, Indore, Madhya Pradesh, India
Run them through the Google Maps API v3 geocoder, they both resolve to the same place (Indore, Madhya Pradesh, India)
If you need to resolve "places" like that, use the Places API to get coordinates, then use the directions service to get directions between the coordinates.
Basically there is a difference in name and address. Google database can have other symbols for the same location. You can read my answer here: http://www.stackoverflow.com/questions/12788664/google-maps-api-geocode-returns-different-co-ordinates-then-google-maps/12790012#12790012. In the google response the name is what you are looking for and in the placemark object the list of address and location in the google database. You need to loop through the placemark object to find the most similar location.

Categories

Resources