当前位置: 首页>>代码示例>>Java>>正文


Java TwitterTemplate类代码示例

本文整理汇总了Java中org.springframework.social.twitter.api.impl.TwitterTemplate的典型用法代码示例。如果您正苦于以下问题:Java TwitterTemplate类的具体用法?Java TwitterTemplate怎么用?Java TwitterTemplate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TwitterTemplate类属于org.springframework.social.twitter.api.impl包,在下文中一共展示了TwitterTemplate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tweets

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
CommandLineRunner tweets(Logger logger, TwitterTemplate twitterTemplate, JdbcTemplate jdbcTemplate) {
    return args -> {
        String screenName = "hintjens";
        int pageSize = 200;
        List<Tweet> userTimeline = twitterTemplate.timelineOperations()
                .getUserTimeline(screenName, pageSize);
        long maxId;
        while (userTimeline.size() != 0 ) {
            maxId = userTimeline.stream()
                    .map(Tweet::getId)
                    .reduce((tweet, tweet2) -> tweet < tweet2 ? tweet : tweet2)
                    .orElse(0L);
            userTimeline = twitterTemplate.timelineOperations()
                    .getUserTimeline(screenName, pageSize, 0L, maxId - 1);
            addAllTweets(jdbcTemplate, userTimeline);
            logger.info("added " + userTimeline.size() + " records.");
        }
    };
}
 
开发者ID:joshlong,项目名称:hintjens-tweets,代码行数:21,代码来源:HintjensApplication.java

示例2: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
// Params injected from application.properties file:
public Twitter twitter(final @Value("${spring.social.twitter.appId}") String appId,
                       final @Value("${spring.social.twitter.appSecret}") String appSecret,
                       final @Value("${spring.social.twitter.accessToken}") String accessToken,
                       final @Value("${spring.social.twitter.accessTokenSecret}") String accessTokenSecret) {
    return new TwitterTemplate(appId, appSecret, accessToken, accessTokenSecret);
}
 
开发者ID:thinksky-sourcecode,项目名称:microservices-prototype,代码行数:9,代码来源:TwitterConfig.java

示例3: twitterTemplate

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
TwitterTemplate twitterTemplate(@Value("${hintjens.consumerKey}") String consumerKey,
                                @Value("${hintjens.consumerSecret}") String consumerSecret,
                                @Value("${hintjens.accessToken}") String accessToken,
                                @Value("${hintjens.accessTokenSecret}") String accessTokenSecret) {
    return new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
}
 
开发者ID:joshlong,项目名称:hintjens-tweets,代码行数:8,代码来源:HintjensApplication.java

示例4: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Twitter twitter(ConnectionRepository repository) {
    Connection<Twitter> connection = repository
            .findPrimaryConnection(Twitter.class);
    if (connection != null) {
        return connection.getApi();
    }
    return new TwitterTemplate(this.properties.getAppId(),
            this.properties.getAppSecret());
}
 
开发者ID:Turbots,项目名称:SpringOne2016,代码行数:13,代码来源:TwitterRedisAutoConfiguration.java

示例5: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Twitter twitter(ConnectionRepository repository) {
	Connection<Twitter> connection = repository
			.findPrimaryConnection(Twitter.class);
	if (connection != null) {
		return connection.getApi();
	}
	return new TwitterTemplate(this.properties.getAppId(),
			this.properties.getAppSecret());
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:13,代码来源:TwitterAutoConfiguration.java

示例6: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
// Params injected from application.properties file:
public Twitter twitter(final @Value("${spring.social.twitter.appId}") String appId,
		final @Value("${spring.social.twitter.appSecret}") String appSecret,
		final @Value("${spring.social.twitter.accessToken}") String accessToken,
		final @Value("${spring.social.twitter.accessTokenSecret}") String accessTokenSecret) {
	return new TwitterTemplate(appId, appSecret, accessToken, accessTokenSecret);
}
 
开发者ID:ivanvs,项目名称:elasticsearch-spring-demo,代码行数:9,代码来源:Application.java

示例7: twitterStream

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
public MessageProducer twitterStream(TwitterTemplate twitterTemplate) {
	TwitterStreamMessageProducer messageProducer =
			new TwitterStreamMessageProducer(twitterTemplate, twitterStreamProperties);
	messageProducer.setOutputChannel(source.output());
	return messageProducer;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:8,代码来源:TwitterstreamSourceConfiguration.java

示例8: twitterTemplate

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Bean
public TwitterTemplate twitterTemplate() {
	TwitterTemplate mockTemplate = mock(TwitterTemplate.class);
	RestTemplate restTemplate = mock(RestTemplate.class);
	final ClientHttpResponse response = mock(ClientHttpResponse.class);
	ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
	try {
		when(response.getBody()).thenReturn(bais);
	}
	catch (IOException e) {
	}
	doAnswer(new Answer<Void>() {

		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			uri().set(invocation.getArgumentAt(0, URI.class));
			ResponseExtractor<?> extractor = invocation.getArgumentAt(3, ResponseExtractor.class);
			extractor.extractData(response);
			return null;
		}

	}).when(restTemplate).execute(any(URI.class), any(HttpMethod.class), any(RequestCallback.class),
			any(ResponseExtractor.class));
	when(mockTemplate.getRestTemplate()).thenReturn(restTemplate);
	return mockTemplate;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:28,代码来源:TwitterSourceIntegrationTests.java

示例9: twitterTemplate

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Bean
@ConditionalOnClass(TwitterTemplate.class)
public TwitterTemplate twitterTemplate() {
	TwitterTemplate mockTemplate = mock(TwitterTemplate.class);
	RestTemplate restTemplate = mock(RestTemplate.class);
	final ClientHttpResponse response = mock(ClientHttpResponse.class);
	ByteArrayInputStream bais = new ByteArrayInputStream("foo".getBytes());
	try {
		when(response.getBody()).thenReturn(bais);
	}
	catch (IOException e) {
	}
	doAnswer(new Answer<Void>() {

		@Override
		public Void answer(InvocationOnMock invocation) throws Throwable {
			ResponseExtractor<?> extractor = invocation.getArgumentAt(3, ResponseExtractor.class);
			extractor.extractData(response);
			return null;
		}

	}).when(restTemplate).execute(any(URI.class), any(HttpMethod.class), any(RequestCallback.class),
			any(ResponseExtractor.class));
	when(mockTemplate.getRestTemplate()).thenReturn(restTemplate);
	return mockTemplate;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-stream-app-starters,代码行数:28,代码来源:TwitterTestConfiguration.java

示例10: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
Twitter twitter(final @Value("${spring.social.twitter.appId}") String appId,
                final @Value("${spring.social.twitter.appSecret}") String appSecret,
                final @Value("${spring.social.twitter.accessToken}") String accessToken,
                final @Value("${spring.social.twitter.accessTokenSecret}") String accessTokenSecret) {
    return new TwitterTemplate(appId, appSecret, accessToken, accessTokenSecret);
}
 
开发者ID:kbastani,项目名称:spring-boot-graph-processing-example,代码行数:8,代码来源:TwitterCrawlerConfig.java

示例11: getTwitterTemplate

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
public TwitterTemplate getTwitterTemplate(Environment env){
    String consumerKey = env.getProperty("opentipbot.notifier.twitter.appKey");
    String consumerSecret = env.getProperty("opentipbot.notifier.twitter.appSecret");
    String accessToken = env.getProperty("opentipbot.notifier.twitter.accessToken");
    String accessTokenSecret = env.getProperty("opentipbot.notifier.twitter.accessTokenSecret");
    Preconditions.checkNotNull(consumerKey);
    Preconditions.checkNotNull(consumerSecret);
    Preconditions.checkNotNull(accessToken);
    Preconditions.checkNotNull(accessTokenSecret);
    return new TwitterTemplate(consumerKey, consumerSecret, accessToken, accessTokenSecret);
}
 
开发者ID:gill3s,项目名称:opentipbot,代码行数:13,代码来源:ServiceSocialConfig.java

示例12: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
Twitter twitter(SelfiesProperties properties) {
    return new TwitterTemplate(properties.getConsumerKey(),
            properties.getConsumerKeySecret(),
            properties.getAccessToken(),
            properties.getAccessTokenSecret());
}
 
开发者ID:joshlong,项目名称:selfies,代码行数:8,代码来源:DemoApplication.java

示例13: importer

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
CommandLineRunner importer(UserRepository userRepository,
                           TweetRepository tweetRepository,
                           TagRepository tagRepository,
                           Neo4jTemplate neo4jTemplate,
                           TwitterTemplate twitterTemplate) {
    return args -> {

        // reset db
        neo4jTemplate.query("MATCH (n) OPTIONAL MATCH (n)-[r]-() DELETE n,r", null);

        // search for tweets matching query ('@SpringBoot')
        SearchResults results = twitterTemplate.searchOperations().search("@SpringBoot", 200);

        results.getTweets().stream().map(source -> {

            User user = userRepository.save(new User(source.getUser()));

            Tweet tweet = new Tweet(source.getId(), user, source.getText());

            source.getEntities().getMentions().forEach((MentionEntity m) -> tweet.addMention(
                    userRepository.save(new User(m.getId(), m.getName(), m.getScreenName()))));

            source.getEntities().getHashTags().forEach((HashTagEntity t) -> tweet.addTag(tagRepository.save(new Tag(t.getText()))));

            return tweetRepository.save(tweet);

        }).forEach(System.out::println);

        userRepository.suggestFriends("starbuxman").forEach(System.out::println);
    };
}
 
开发者ID:joshlong,项目名称:graphconnect-2014,代码行数:33,代码来源:Application.java

示例14: twitter

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
@Bean
public Twitter twitter(final @Value("${spring.social.twitter.appId}") String appId,
                       final @Value("${spring.social.twitter.appSecret}") String appSecret) {
    return new TwitterTemplate(appId, appSecret);
}
 
开发者ID:qaware,项目名称:cloud-native-zwitscher,代码行数:6,代码来源:SocialZwitscherConfiguration.java

示例15: SearchController

import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
public SearchController(TwitterTemplate twitterTemplate) {
    this.twitterTemplate=twitterTemplate;
}
 
开发者ID:RawSanj,项目名称:spring-twitter-stream,代码行数:4,代码来源:SearchController.java


注:本文中的org.springframework.social.twitter.api.impl.TwitterTemplate类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。