I'm using Twitter4j to access the Twitter streaming API, and I want to limit the tweets I get from the sample stream to English language tweets. I had thought that the way to do this would be as follows, based on the Javadoc:
FilterQuery fq = new FilterQuery();
String[] lang = { "en" };
fq.language(lang);// = "test";
twitterStream.filter(fq);
But, when I try and run that, I get a compiler error saying the FilterQuery objects don't have a public language method. Does anyone know what's going on?
Edit: I'm using version 3.0.3 of the JAR file
That feature has not been implemented yet. There's an open ticket TFJ-764 as part of the 3.0.4 for supporting tweet's metadata.
Related
I've updated to elasticsearch java library version 5.2.0.
In 2.x,
I was using SearchRequestBuilder.addField() in order to add a field to the search request. Nevertheless, It seems to be replaced. I've written the available methods intellisense is showing me. Which of them do I need to pick?
addDocValueField
addFieldDataField
addScriptField
addStoredField
storedFields
fields
SearchRequestBuilder.setNoFields is also removed. Which would be the alternative?
Currently, I'm calling scripts from Java using this code. Is there any more elegant way to call it in 5.x Java API?
Code:
return AggregationBuilders
.terms(this.getName())
.field(this.getName())
.script(new Script(
ScriptType.FILE,
"painless",
"year",
ImmutableMap.of("field", this.getName())
)
);
As you can see I setting field as script parameter. Nevertheless, I don't quite understand how to get it from script code.
Thanks.
When in doubt, go to the source
use setFetchSource(String[] includes, String[] excludes) instead
use setFetchSource(false) instead
if you need to execute this script for each document, you can use addScriptField()
I am trying to implement Google Webmasters Searchanalytics Query using using the Java API but i did not found any Java sample to use , in Google website here there is only Python samples for Searchanalytics Query , and they did not say that it's not available in Java API.
I found this class Webmasters.Searchanalytics.Query in the Java API which I assume that is equivalent to the Python function searchanalytics.query() but i did not found any implementation of it.
My question if it is possible to query data from Google Search Console using the Java API??
if yes i wounder if there is someone who can provide a Java sample, something like the Python sample provided by Google here.
Thank you in advance.
I succeded to implement Webmasters.Searchanalytics.Query
as follow
first you need to create your QueryRequest using the SearchAnalyticsQueryRequest class example:
private static SearchAnalyticsQueryRequest createSearchAnalyticsQueryRequest() {
SearchAnalyticsQueryRequest searQueryRequest = new SearchAnalyticsQueryRequest();
searQueryRequest.setStartDate("2016-04-10");
searQueryRequest.setEndDate("2016-04-20");
List<String> dimensions = new ArrayList<String>();
dimensions.add("page");
dimensions.add("query");
dimensions.add("country");
dimensions.add("device");
dimensions.add("date");
searQueryRequest.setDimensions(dimensions);
return searQueryRequest;
}
then executing the query as follow :
public static String Query(String site,
SearchAnalyticsQueryRequest searQueryRequest) throws Exception {
Webmasters.Searchanalytics.Query query = service.searchanalytics()
.query(site, searQueryRequest);
SearchAnalyticsQueryResponse queryResponse = query.execute();
return queryResponse.toPrettyString();
}
I think You missed it. here. Actually all you need to do is to click the Java link on the left.
Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.
Analysis api takes fieldName or fieldType and values and give the analyzed tokens.
Is there a way to get those tokens from java?
I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.
In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry.
See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.
From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL.
Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.
From Solrj it should work like this:
SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);
But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.
This is a very basic beginner question, but I checked the main API site (https://developers.google.com/youtube/v3/) pretty thoroughly and messed around for quite a frustrating while with the sample code, used Google to find other working examples and I came up with nothing so I decided to ask here.
My aim is to write a simple Java program that connects to a YouTube account and retrieves the names and contents of the user's playlists, then possibly saves them to a text file or w/e.
I didn't find much on the site to explain exactly what steps are involved in properly connecting to a YouTube account through Java, so I tried running some sample code. If I take this for example:
https://developers.google.com/youtube/v3/code_samples/java#retrieve_my_uploads
And paste it into Eclipse, it tells me the following:
The type "FileCredentialStore" is deprecated.
At the following method:
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load( JSON_FACTORY, MyUploads.class.getResourceAsStream("/client_secrets.json"));
It tells me:
"The method load(JsonFactory, Reader) in the type GoogleClientSecrets is not applicable for the arguments (JsonFactory, InputStream)"
A bit of Googling led me somewhere that suggested the method used in the example which uses an InputStream was deprecated and later removed in 1.16 I believe.
Later the following error occurs:
channelRequest.setMine("true");
Where the String "true", should be the boolean value true. Again I'm assuming a previous version of that method was deprecated.
I've tried messing around with it, trying to piece things together from Google but it hasn't worked at all. The code seems to be outdated and not to work with the latest version of the API, and most code I can find online seems old too. I don't know enough about what I'm doing and I can't find any documentation that actually outlines what steps are required, why, and how they work.
For instance, I can't figure out what client_secrets.json is for and how it's supposed to be set up, beyond it being a part of authentication. If the API site explained it fully, I couldn't find where.
Does anyone know of a site with some working up-to-date sample code that performs some simple connection and data retrieval? Or a proper step-by-step guide that explains how to connect?
I would've thought something like the YouTube API would be straightforward and well-documented but I just can't get my head around it, unless I've missed something important but I'm out of ideas.
Google API says:
load method with InputStream is Deprecated. (scheduled to be removed in 1.16) Use load(JsonFactory, Reader) instead. Source
Thus convert InputStream to Reader and problem solved
private static GoogleClientSecrets loadClientSecrets(String clientSecretsLocation) {
try {
Reader reader = new InputStreamReader(BigQueryJavaGettingStarted.class.getResourceAsStream(clientSecretsLocation));
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(new JacksonFactory(),
reader);
} catch (Exception e) {
System.out.println("Could not load client_secrets.json");
e.printStackTrace();
}
return clientSecrets;
}
I would like to retrieve or filter by language using TwitterStream class. I want to get only tweets of one language or otherwise retrieve everything and then identify each tweet language.
I have build this code but getIsoLanguageCode() returns null always (see version 3.0.4 JavaDocs). I think they have problems with this method.
TwitterStream twitterStream = TwitterPrintRandomStream.createTwitterConnection();
StatusListener listener = new StatusListener() {
public void onStatus(Status status) {
String tw = status.getText() + " " + status.getIsoLanguageCode();
System.out.println(tw);
}
...
}
I also tried the method Status.getUser().getLang() but it returns the user's language not the tweet. Is there any way to do it?
Thanks in advance.
I don't think you can rely on iso_language_code - I couldn't find reference to it in the REST or streaming APIs.
Tweets do have a lang attribute which indicates the language that the Tweet was written in. This was recently added to the API and, unfortunately, Twitter4J does not yet provide you with access to it.
There is a task to add it in version 3.0.4 but the work does not to appear to have started yet. Unfortunately you'll need to wait until they add it or perhaps you could give them a hand and submit a pull-request.
status.getPlace().getCountryCode() should do the trick to get ISO 3166-1 alpha 2 country code
First, Try to get status.getLang() and put em into String then compare it with status.getText() if match you can get the tweets that only contain language in status.getLang()
You can try this following code
String filterTweet=null
String language= status.getLang()
String filterLang="(language code)"
If (filterLang.Matches(language)){
filterTweet=status.getText()}
Cya