This module provides couple of twitter functions that can be reused and composed in other applications.
To use those functions add the following dependency to your POM:
<dependency>
<groupId>org.springframework.cloud.fn</groupId>
<artifactId>twitter-function</artifactId>
<version>${java-functions.version}</version>
</dependency>
Functions can return either Trends topics or the Locations of the trending topics. The twitter.trend.trend-query-type
property allows choosing between both types.
-
Trends -
twitter.trend.trend-query-type
is set totrend
. Leverages the Trends API to return the trending topics near a specific latitude, longitude location. -
Trend Locations - the
twitter.trend.trend-query-type
is settrendLocation
. Retrieve a full or nearby locations list of trending topics by location. If thelatitude
,longitude
parameters are NOT provided the processor performs the Trends Available API and returns the locations that Twitter has trending topic information for. If thelatitude
,longitude
parameters are provided the processor performs the Trends Closest API and returns the locations that Twitter has trending topic information for, closest to a specified location.
Response is an array of locations
that encode the location’s WOEID and some other human-readable information such as a canonical name and country the location belongs in.
You can import the TwitterTrendFunctionConfiguration
in a Spring Boot application and then inject the following bean.
filterFunction
You can use Function<Message<?>, Message<byte[]>> twitterTrendFunction
as a qualifier when injecting.
Once injected, you can use the apply
method of the Function
to invoke it and get the result.
Tip
|
For SpEL expression properties wrap the literal values in single quotes (' ).
|
For more information on the various options available, please see TwitterTrendFunctionProperties.java
See this test suite for examples of how this function is used.
Leveraging the Spring Cloud Function composability, you can compose the Trend function in your boot app like this:
@SpringBootApplication
@Import(TwitterTrendFunctionConfiguration.class )
public class MyTwitterTrendBootApp {
public static void main(String[] args) {
SpringApplication.run(MyTwitterTrendBootApp.class,
"--spring.cloud.function.definition=trend|twitterTrendFunction|managedJson");
}
}
Function based on the Geo API that retrieves Twitter place information based on query parameters such as (latitude
, longitude
) pair, an IP
address, or a place name
.
There are two types for geo search queries search
and reverse
controlled by the twitter.geo.search.type
property.
-
reverse - Given a latitude and a longitude, searches for up to 20 places that can be used as a
placeId
when updating a status. This request is an informative call and will deliver generalized results about geography. -
search - Search for places that can be attached to statuses/update. Given a latitude and a longitude pair, an IP address, or a name, this request will return a list of all the valid places that can be used as the place_id when updating a status.
Conceptually, a query can be made from the user’s location, retrieve a list of places, have the user validate the location he or she is at, and then send the ID of this location with a call to POST statuses/update.
This is the recommended method to use find places that can be attached to statuses/update. Unlike GET geo/reverse_geocode which provides raw data access, this endpoint can potentially re-order places with regard to the user who is authenticated. Use this approach for interactive place matching with the user.
Some parameters in this method are only required based on the existence of other parameters. For instance, “lat” is required if “long” is provided, and vice-versa. Authentication is recommended, but not required with this method.
Note
|
Limits: 15 requests / 15-min window (user auth). |
You can import the TwitterGeoFunctionConfiguration
in a Spring Boot application and then inject the following bean.
filterFunction
You can use Function<Message<?>, Message<byte[]>> twitterGeoFunction
as a qualifier when injecting.
Once injected, you can use the apply
method of the Function
to invoke it and get the result.
Tip
|
For SpEL expression properties wrap the literal values in single quotes (' ).
|
For more information on the various options available, please see TwitterGeoFunctionProperties.java
See this test suite for examples of how this function is used.
Leveraging the Spring Cloud Function composability, you can compose the Geo function in your boot app like this:
@SpringBootApplication
@Import(TwitterGeoFunctionConfiguration.class )
public class MyTwitterGeoProcessorBootApp {
public static void main(String[] args) {
SpringApplication.run(MyTwitterGeoProcessorBootApp.class,
"--spring.cloud.function.definition=messageToGeoQueryFunction|twitterSearchPlacesFunction|managedJson");
}
}
Retrieves users either by list of use ids and/or screen-names (Users Lookup API) or by text search query (Users Search API). Uses SpEL expressions to compute the query parameters from the input message. Use the single quoted literals to set static values (e.g. user-id: '6666, 9999, 10000').
Use twitter.users.type
property allow to select the query approaches.
-
Users Lookup API - Returns fully-hydrated user objects for up to 100 users per request, as specified by comma-separated values passed to the
userId
and/orscreenName
parameters. Rate limits: (300 requests / 15-min window) -
Users Search API - Relevance-based search interface to public user accounts on Twitter. Querying by topical interest, full name, company name, location, or other criteria. Exact match searches are not supported. Only the first 1,000 matching results are available. Rate limits:(900 requests / 15-min window)
You can import the TwitterUsersFunctionConfiguration
in a Spring Boot application and then inject the following bean.
filterFunction
You can use Function<Message<?>, Message<byte[]>> twitterUsersFunction
as a qualifier when injecting.
Once injected, you can use the apply
method of the Function
to invoke it and get the result.
Tip
|
For SpEL expression properties wrap the literal values in single quotes (' ).
|
For more information on the various options available, please see TwitterUsersFunctionProperties.java
See this test suite for examples of how this function is used.