热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

twitter4j.TwitterFactory.getInstance()方法的使用及代码示例

本文整理了Java中twitter4j.TwitterFactory.getInstance()方法的一些代码示例,展示了TwitterFactory.ge

本文整理了Java中twitter4j.TwitterFactory.getInstance()方法的一些代码示例,展示了TwitterFactory.getInstance()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。TwitterFactory.getInstance()方法的具体详情如下:
包路径:twitter4j.TwitterFactory
类名称:TwitterFactory
方法名:getInstance

TwitterFactory.getInstance介绍

[英]Returns a instance associated with the configuration bound to this factory.
[中]返回与绑定到此工厂的配置关联的实例。

代码示例

代码示例来源:origin: google/data-transfer-project

static Twitter getInstance(
AppCredentials appCredentials,
TokenSecretAuthData authData) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(false)
.setOAuthConsumerKey(appCredentials.getKey())
.setOAuthConsumerSecret(appCredentials.getSecret())
// TODO: I think the token/secret expire, we need to check into refreshing them
.setOAuthAccessToken(authData.getToken())
.setOAuthAccessTokenSecret(authData.getSecret());
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
}
}

代码示例来源:origin: org.twitter4j/twitter4j-async

AsyncTwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
twitter = new TwitterFactory(conf).getInstance(auth);
}

代码示例来源:origin: org.apache.camel/camel-twitter

public Twitter getTwitter() {
if (twitter == null) {
twitter = new TwitterFactory(getConfiguration()).getInstance();
}
return twitter;
}

代码示例来源:origin: openimaj/openimaj

/**
* @param token
* @param buffer
*/
protected AbstractTwitterSearchDataset(TwitterAPIToken token, BlockingDroppingQueue buffer, Query query) {
super(buffer);
this.cOnfig= makeConfiguration(token);
this.twitter = new TwitterFactory(config).getInstance();
this.query = query;
startSearch();
}

代码示例来源:origin: stackoverflow.com

TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
twitter.setOAuthConsumer("[consumer key]", "[consumer secret]");
AccessToken accessToken = loadAccessToken();
twitter.setOAuthAccessToken(accessToken);

代码示例来源:origin: org.openimaj/twitter

/**
* @return create a {@link Twitter} instance using the tokens from
* {@link DefaultTokenFactory}
*/
public static Twitter create() {
Twitter INSTANCE = null;
if (INSTANCE == null) {
final Configuration cOnfig= makeConfiguration(DefaultTokenFactory.get(TwitterAPIToken.class));
INSTANCE = new TwitterFactory(config).getInstance();
}
return INSTANCE;
}

代码示例来源:origin: openimaj/openimaj

/**
* @return create a {@link Twitter} instance using the tokens from
* {@link DefaultTokenFactory}
*/
public static Twitter create() {
Twitter INSTANCE = null;
if (INSTANCE == null) {
final Configuration cOnfig= makeConfiguration(DefaultTokenFactory.get(TwitterAPIToken.class));
INSTANCE = new TwitterFactory(config).getInstance();
}
return INSTANCE;
}

代码示例来源:origin: ORCID/ORCID-Source

/**
* Get the twitter RequestToken
*
* @return The twitter RequestToken
* */
private RequestToken getTwitterRequestToken(String orcid) throws Exception {
// If it exists, use it once and discard it
if (requestTokenMap.containsKey(orcid)) {
RequestToken result = requestTokenMap.get(orcid);
requestTokenMap.remove(orcid);
return result;
} else {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(twitterKey, twitterSecret);
RequestToken requestToken = twitter.getOAuthRequestToken();
requestTokenMap.put(orcid, requestToken);
return requestToken;
}
}

代码示例来源:origin: apache/asterixdb

public static Twitter getTwitterService(Map configuration) {
ConfigurationBuilder cb = getAuthConfiguration(configuration);
TwitterFactory tf = null;
try {
tf = new TwitterFactory(cb.build());
} catch (Exception e) {
if (LOGGER.isWarnEnabled()) {
StringBuilder builder = new StringBuilder();
builder.append("Twitter Adapter requires the following config parameters\n");
builder.append(AuthenticationConstants.OAUTH_CONSUMER_KEY + "\n");
builder.append(AuthenticationConstants.OAUTH_CONSUMER_SECRET + "\n");
builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN + "\n");
builder.append(AuthenticationConstants.OAUTH_ACCESS_TOKEN_SECRET + "\n");
LOGGER.warn(builder.toString());
LOGGER.warn(
"Unable to configure Twitter adapter due to incomplete/incorrect authentication credentials");
LOGGER.warn(
"For details on how to obtain OAuth authentication token, visit https://dev.twitter.com/oauth"
+ "/overview/application-owner-access-tokens");
}
}
Twitter twitter = tf.getInstance();
return twitter;
}

代码示例来源:origin: ORCID/ORCID-Source

/**
* Get the twitter AccessToken
*
* @return The twitter AccessToken
* */
private AccessToken getOAuthAccessToken(String orcid, String pin) throws Exception {
RequestToken requestToken = getTwitterRequestToken(orcid);
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(twitterKey, twitterSecret);
return twitter.getOAuthAccessToken(requestToken, pin);
}

代码示例来源:origin: stackoverflow.com

ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRETE)
// accessTokenKey and accessTokenSecrete are what you get after redirecting
// back from your oauthentication
.setOAuthAccessToken(accessTokenKey)
.setOAuthAccessTokenSecret(accessTokenSecrete)
.setMediaProviderAPIKey(TWITPIC_API_KEY);
Configuration cOnfig= cb.build();
TwitterFactory tf = new TwitterFactory(config);
Twitter twitter = tf.getInstance();

代码示例来源:origin: org.tomitribe/chatterbox-twitter-impl

public void start(final BootstrapContext bootstrapContext) throws ResourceAdapterInternalException {
LOGGER.info("Starting " + this);
client = new TwitterStreamingClient(this, consumerKey, consumerSecret, accessToken, accessTokenSecret);
twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
twitter.setOAuthAccessToken(new AccessToken(accessToken, accessTokenSecret));
try {
client.run();
} catch (InterruptedException | ControlStreamException | IOException e) {
e.printStackTrace();
}
}

代码示例来源:origin: checkstyle/contribution

/**
* Publish post.
* @throws TwitterException if an error occurs while publishing.
* @throws IOException if there are problems with reading file with the post text.
*/
public void publish() throws TwitterException, IOException {
final Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
final AccessToken token = new AccessToken(accessToken, accessTokenSecret);
twitter.setOAuthAccessToken(token);
final String post = new String(Files.readAllBytes(Paths.get(postFilename)),
StandardCharsets.UTF_8);
twitter.updateStatus(post);
}
}

代码示例来源:origin: nl.cloudfarming.client/twitter

private Image getImage(User user) {
ProfileImage.ImageSize imageSize = ProfileImage.MINI;
try {
Twitter twitter = new TwitterFactory().getInstance();
ProfileImage image = twitter.getProfileImage(user.getScreenName(), imageSize);
Image img = ImageIO.read(new URL(image.getURL()));
if (img == null){
img = ImageUtilities.loadImage("nl/cloudfarming/client/twitter/twitter_newbird_blue.png");
}else{
return img;
}
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
} catch (TwitterException te) {
Exceptions.printStackTrace(te);
}
return null;
}
}

代码示例来源:origin: stackoverflow.com

if (!isLoggedIn) {
final ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(consumerKey);
builder.setOAuthConsumerSecret(consumerSecret);
final Configuration cOnfiguration= builder.build();
final TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
requestToken = twitter.getOAuthRequestToken(callbackUrl);
final Intent intent = new Intent(getActivity(), WebViewActivity.class);
intent.putExtra(WebViewActivity.EXTRA_URL, requestToken.getAuthenticationURL());
startActivityForResult(intent, WEBVIEW_REQUEST_CODE);
} catch (TwitterException e) {
e.printStackTrace();
}
}

代码示例来源:origin: stackoverflow.com

TwitterFactory factory = new TwitterFactory();
Twitter twitter = factory.getInstance();
String twitterScreenName;
try {
twitterScreenName = twitter.getScreenName();
IDs followerIDs = twitter.getFollowersIDs(twitterScreenName, -1);
long[] ids = followerIDs.getIDs();
for (long id : ids) {
twitter4j.User user = twitter.showUser(id);
//here i am trying to fetch the followers of each id
String userScreenName = user.getScreenName();
System.out.println("Name: " + user.getScreenName());
System.out.println("Location:" + user.getLocation());
IDs followerIDsOfFollowers = twitter.getFollowersIDs(user.getScreenName(), -1);
long[]fofIDs = followerIDsOfFollowers.getIDs();
for(long subId : fofIDs) {
twitter4j.User user1 = twitter.showUser(subId);
System.out.println("Follower Master:" + userScreenName +" Follower of Follower Name: " + user1.getScreenName());
System.out.println("Location:" + user1.getLocation());
}

代码示例来源:origin: stackoverflow.com

public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey("Your Cosumer Key")
.setOAuthConsumerSecret("Your Consumer Secret")
.setOAuthAccessToken("Your Access Token")
.setOAuthAccessTokenSecret("Your Access Token Secret");
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
Twitter twitter = new TwitterFactory().getInstance();
List statusList = null;
try {
statusList = twitter.getUserTimeline("@Citi");
} catch (TwitterException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
for (Status status : statusList) {
System.out.println(status.toString());
}
}

代码示例来源:origin: stackoverflow.com

private void loginToTwitter() {
// Check if already logged in
if (!isTwitterLoggedInAlready()) {
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
Configuration cOnfiguration= builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
requestToken = twitter
.getOAuthRequestToken(TWITTER_CALLBACK_URL);
this.startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri
.parse(requestToken.getAuthenticationURL())), TWITER);
Intent i = new intent(reditectedActivity.class, thisActivity.this);
startActivity(i);
} catch (TwitterException e) {
e.printStackTrace();
}
} else {
// user already logged into twitter
Toast.makeText(getApplicationContext(),
"Already Logged into twitter", Toast.LENGTH_LONG).show();
}
}

代码示例来源:origin: stackoverflow.com

Configuration cOnfiguration= builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();

代码示例来源:origin: stackoverflow.com

ConfigurationBuilder cOnfigurationBuilder= new ConfigurationBuilder();
configurationBuilder
.setOAuthConsumerKey(STAConstants.TWITTER_CONSUMER_KEY);
configurationBuilder
.setOAuthConsumerSecret(STAConstants.TWITTER_CONSUMER_SECRET);
Configuration cOnfiguration= configurationBuilder.build();
TwitterFactory twitterFactory = new TwitterFactory(configuration);
Twitter twitter = twitterFactory.getInstance();
AccessToken accessToken = new AccessToken("ACCESS_TOKEN","TOKEN_SECRET");
twitter.setOAuthAccessToken(accessToken);
System.out.println(twitter.getUserTimeline("twitter"));

推荐阅读
author-avatar
济南谷幽兰
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有