本文整理汇总了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.");
}
};
}
示例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);
}
示例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);
}
示例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());
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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());
}
示例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);
};
}
示例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);
}
示例15: SearchController
import org.springframework.social.twitter.api.impl.TwitterTemplate; //导入依赖的package包/类
public SearchController(TwitterTemplate twitterTemplate) {
this.twitterTemplate=twitterTemplate;
}