本文整理汇总了Java中com.twitter.hbc.httpclient.auth.OAuth1类的典型用法代码示例。如果您正苦于以下问题:Java OAuth1类的具体用法?Java OAuth1怎么用?Java OAuth1使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OAuth1类属于com.twitter.hbc.httpclient.auth包,在下文中一共展示了OAuth1类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: configureStreamClient
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
private static BasicClient configureStreamClient(BlockingQueue<String> msgQueue, String twitterKeys, List<Long> userIds, List<String> terms) {
Hosts hosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint()
.followings(userIds)
.trackTerms(terms);
endpoint.stallWarnings(false);
String[] keys = twitterKeys.split(":");
Authentication auth = new OAuth1(keys[0], keys[1], keys[2], keys[3]);
ClientBuilder builder = new ClientBuilder()
.name("Neo4j-Twitter-Stream")
.hosts(hosts)
.authentication(auth)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(msgQueue));
return builder.build();
}
示例2: getTwitterClient
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
private Client getTwitterClient(Properties props, BlockingQueue<String> messageQueue) {
String clientName = props.getProperty("clientName");
String consumerKey = props.getProperty("consumerKey");
String consumerSecret = props.getProperty("consumerSecret");
String token = props.getProperty("token");
String tokenSecret = props.getProperty("tokenSecret");
List<String> searchTerms = Arrays.asList(props.getProperty("searchTerms").split(","));
Authentication authentication = new OAuth1(consumerKey,consumerSecret,token,tokenSecret);
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint hosebirdEndpoint = new StatusesFilterEndpoint();
hosebirdEndpoint.trackTerms(searchTerms);
ClientBuilder clientBuilder = new ClientBuilder();
clientBuilder.name(clientName)
.hosts(hosebirdHosts)
.authentication(authentication)
.endpoint(hosebirdEndpoint)
.processor(new StringDelimitedProcessor(messageQueue));
return clientBuilder.build();
}
示例3: oAuth
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
private static Authentication oAuth() {
final Properties properties = new Properties();
final String fileName = "config.properties";
final InputStream is = TwitterStream.class.getClassLoader().getResourceAsStream(fileName);
if (is != null) {
try {
properties.load(is);
} catch (IOException e) {
System.err.println(e.getMessage());
}
} else {
System.err.println("property file '" + fileName + "' not found in the classpath");
}
final String consumerKey = properties.getProperty("consumerKey");
final String consumerSecret = properties.getProperty("consumerSecret");
final String accessToken = properties.getProperty("accessToken");
final String accessTokenSecret = properties.getProperty("accessTokenSecret");
Authentication hosebirdAuth = new OAuth1(consumerKey, consumerSecret, accessToken, accessTokenSecret);
return hosebirdAuth;
}
示例4: setupHosebirdClient
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public static void setupHosebirdClient() {
/** Declare the host you want to connect to, the endpoint, and authentication (basic auth or oauth) */
Hosts hosebirdHosts = new HttpHosts(Constants.STREAM_HOST);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
// Optional: set up some followings and track terms
List<Long> followings = Lists.newArrayList(1234L, 566788L);
List<String> terms = Lists.newArrayList("twitter", "api");
endpoint.followings(followings);
endpoint.trackTerms(terms);
Authentication hosebirdAuth = new OAuth1(
Helper.properties().getProperty("consumerKey"),
Helper.properties().getProperty("consumerSecret"),
Helper.properties().getProperty("token"),
Helper.properties().getProperty("secret"));
ClientBuilder builder = new ClientBuilder()
.name("Hosebird-Client-01") // optional: mainly for the logs
.hosts(hosebirdHosts)
.authentication(hosebirdAuth)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(msgQueue));
hosebirdClient = builder.build();
}
示例5: start
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
@Override
public void start() {
OAuth1 auth = new OAuth1(
config.getProperty("oauth.consumer.key"),
config.getProperty("oauth.consumer.secret"),
config.getProperty("oauth.token"),
config.getProperty("oauth.secret"));
System.out.println(config.getProperty("oauth.consumer.key"));
client = new ClientBuilder()
.name("bask-twitter-feed")
.hosts(Constants.STREAM_HOST)
.endpoint(new StatusesSampleEndpoint())
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
client.connect();
pollTweets();
}
示例6: streamTwitter
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public static void streamTwitter(String consumerKey, String consumerSecret, String accessToken, String accessSecret) throws InterruptedException {
BlockingQueue<String> statusQueue = new LinkedBlockingQueue<String>(10000);
StatusesSampleEndpoint ending = new StatusesSampleEndpoint();
ending.stallWarnings(false);
Authentication twitterAuth = new OAuth1(consumerKey, consumerSecret, accessToken, accessSecret);
BasicClient twitterClient = new ClientBuilder()
.name("Twitter client")
.hosts(Constants.STREAM_HOST)
.endpoint(ending)
.authentication(twitterAuth)
.processor(new StringDelimitedProcessor(statusQueue))
.build();
twitterClient.connect();
for (int msgRead = 0; msgRead < 1000; msgRead++) {
if (twitterClient.isDone()) {
System.out.println(twitterClient.getExitEvent().getMessage());
break;
}
String msg = statusQueue.poll(10, TimeUnit.SECONDS);
if (msg == null) {
System.out.println("Waited 10 seconds - no message received");
} else {
System.out.println(msg);
}
}
twitterClient.stop();
System.out.printf("%d messages processed!\n", twitterClient.getStatsTracker().getNumMessages());
}
开发者ID:PacktPublishing,项目名称:Machine-Learning-End-to-Endguide-for-Java-developers,代码行数:40,代码来源:SampleStreamExample.java
示例7: initializeConnection
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
@Override
protected void initializeConnection() {
if (LOG.isInfoEnabled()) {
LOG.info("Initializing Twitter Streaming API connection");
}
this.queue = new LinkedBlockingQueue(this.queueSize);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(false)
.locations(Arrays.asList(
new Location(
// europa: -32.0 34.0 40.0 75.0
new Location.Coordinate(-32.0, 34.0), // south west
new Location.Coordinate(40.0, 75.0))
// new Location(
// // north america: -168.48633, 13.23995 -50.36133, 72.76406
// new Location.Coordinate(-168.48633, 13.23995), // south west
// new Location.Coordinate(-50.36133, 72.76406))
)
);
endpoint.stallWarnings(false);
OAuth1 auth = this.authenticate();
this.initializeClient(endpoint, auth);
if (LOG.isInfoEnabled()) {
LOG.info("Twitter Streaming API connection established successfully");
}
}
示例8: startFiltering
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public void startFiltering() {
List<Job> jobs = jobRepository.findAll();
log.info("There are " + jobs.size() + " jobs in the database.");
if (jobs.size() == 0) {
log.error("No jobs found at the database. Please define some jobs first.");
return;
}
BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
List<String> keywords = new ArrayList<>();
for (Job j : jobs) {
keywords.addAll(j.getKeywords());
}
endpoint.trackTerms(keywords);
Authentication auth = new OAuth1(consumerKey, consumerSecret, accessToken, accessSecret);
this.client = new ClientBuilder().hosts(Constants.STREAM_HOST).endpoint(endpoint).authentication(auth)
.processor(new StringDelimitedProcessor(queue)).build();
int numProcessingThreads = 4;
ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);
List<StatusListener> listeners = new ArrayList<>();
listeners.add(statusStreamHandlerImpl.createListener());
Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(client, queue, listeners, service);
t4jClient.connect();
for (int threads = 0; threads < numProcessingThreads; threads++) {
t4jClient.process();
}
}
示例9: start
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
@Override
public TwitterAggregator start(final String... keywords) {
final BlockingQueue<String> queue = new LinkedBlockingQueue<>(10000);
final Authentication auth = new OAuth1(
consumerKey,
consumerSecret,
token,
tokenSecret);
// Create a new BasicClient. By default gzip is enabled.
final ClientBuilder builder = new ClientBuilder()
.hosts(Constants.STREAM_HOST)
.endpoint(new StatusesFilterEndpoint().trackTerms(Lists.newArrayList(keywords)))
.authentication(auth)
.processor(new StringDelimitedProcessor(queue));
// Wrap our BasicClient with the twitter4j client
client = new Twitter4jStatusClient(
builder.build(),
queue,
Collections.singletonList(new TwitterMessageListener()),
C1Services.getInstance().getExecutorService());
client.connect();
client.process();
return this;
}
示例10: buildClient
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
/**
* @param tweetQueue tweet Queue.
* @param hosts Hostes.
* @param endpoint Endpoint.
* @return Client.
*/
protected Client buildClient(BlockingQueue<String> tweetQueue, HttpHosts hosts, StreamingEndpoint endpoint) {
Authentication authentication = new OAuth1(oAuthSettings.getConsumerKey(), oAuthSettings.getConsumerSecret(),
oAuthSettings.getAccessToken(), oAuthSettings.getAccessTokenSecret());
ClientBuilder builder = new ClientBuilder()
.name("Ignite-Twitter-Client")
.hosts(hosts)
.authentication(authentication)
.endpoint(endpoint)
.processor(new StringDelimitedProcessor(tweetQueue));
return builder.build();
}
示例11: start
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public void start(String hashtag) {
BlockingQueue<String> queue = new LinkedBlockingQueue<>(10000);
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
endpoint.stallWarnings(false);
StatusesFilterEndpoint filterEndpoint = new StatusesFilterEndpoint();
List<String> terms = Lists.newArrayList(hashtag);
filterEndpoint.trackTerms(terms);
String consumerKey = System.getProperty("twitter.consumerKey", "");
String consumerSecret = System.getProperty("twitter.consumerSecret", "");
String token = System.getProperty("twitter.token", "");
String tokenSecret = System.getProperty("twitter.tokenSecret", "");
Authentication auth = new OAuth1(consumerKey,consumerSecret,token,tokenSecret);
client = new ClientBuilder()
.name("JDG #" + hashtag + " client")
.hosts(Constants.STREAM_HOST)
.endpoint(filterEndpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
TwitterReader reader = new TwitterReader(client, queue, cache, timeout);
executor = Executors.newSingleThreadExecutor();
executor.execute(reader);
}
示例12: collect
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public void collect() throws IOException {
final BlockingQueue<String> queue = new LinkedBlockingQueue<>(QUEUE_SIZE);
final StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
// Set location to collect on
endpoint.locations(Lists.newArrayList(COLLECTION_LOCATION));
// add some track terms with this code:
// endpoint.trackTerms(Lists.newArrayList("twitterapi", "#yolo"));
final Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
// Create a new BasicClient. By default gzip is enabled.
final Client client = new ClientBuilder()
.hosts(Constants.STREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Establish a connection
client.connect();
while (!client.isDone()) {
writeTweetsToFile(getFileToWrite(), queue);
}
client.stop();
log.info("Client stopped, restart needed");
}
示例13: activate
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public void activate()
{
synchronized (_pauseSyncObject)
{
try
{
_tweetQueue = new LinkedBlockingQueue<String>(TWEETQUEUESIZE);
StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint();
endpoint.trackTerms(Lists.newArrayList(_trackTerm));
Authentication authentication = new OAuth1(_consumerKey, _consumerSecret, _token, _tokenSecret);
ClientBuilder twitterClientBuilder = new ClientBuilder();
twitterClientBuilder.name("DataBrokerClient");
twitterClientBuilder.hosts(Constants.STREAM_HOST);
twitterClientBuilder.endpoint(endpoint);
twitterClientBuilder.authentication(authentication);
twitterClientBuilder.processor(new StringDelimitedProcessor(_tweetQueue));
_twitterClient = twitterClientBuilder.build();
_twitterClient.connect();
}
catch (Throwable throwable)
{
logger.log(Level.WARNING, "TwitterDataSource: Configuring problem \"" + _name + "\"", throwable);
_twitterClient = null;
_tweetQueue = null;
}
_fetch = true;
_pauseSyncObject.notify();
}
}
示例14: authenticate
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
private OAuth1 authenticate() {
Properties authenticationProperties = loadAuthenticationProperties();
return new OAuth1(authenticationProperties.getProperty("consumerKey"),
authenticationProperties.getProperty("consumerSecret"),
authenticationProperties.getProperty("token"),
authenticationProperties.getProperty("secret"));
}
示例15: oauth
import com.twitter.hbc.httpclient.auth.OAuth1; //导入依赖的package包/类
public void oauth(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException {
// Create an appropriately sized blocking queue
BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000);
// Define our endpoint: By default, delimited=length is set (we need this for our processor)
// and stall warnings are on.
StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint();
Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret);
// Authentication auth = new BasicAuth(username, password);
// Create a new BasicClient. By default gzip is enabled.
BasicClient client = new ClientBuilder()
.hosts(Constants.STREAM_HOST)
.endpoint(endpoint)
.authentication(auth)
.processor(new StringDelimitedProcessor(queue))
.build();
// Create an executor service which will spawn threads to do the actual work of parsing the incoming messages and
// calling the listeners on each message
int numProcessingThreads = 4;
ExecutorService service = Executors.newFixedThreadPool(numProcessingThreads);
// Wrap our BasicClient with the twitter4j client
Twitter4jStatusClient t4jClient = new Twitter4jStatusClient(
client, queue, Lists.newArrayList(listener1, listener2), service);
// Establish a connection
t4jClient.connect();
for (int threads = 0; threads < numProcessingThreads; threads++) {
// This must be called once per processing thread
t4jClient.process();
}
Thread.sleep(5000);
client.stop();
}