本文整理匯總了Java中twitter4j.conf.ConfigurationBuilder.setOAuthConsumerKey方法的典型用法代碼示例。如果您正苦於以下問題:Java ConfigurationBuilder.setOAuthConsumerKey方法的具體用法?Java ConfigurationBuilder.setOAuthConsumerKey怎麽用?Java ConfigurationBuilder.setOAuthConsumerKey使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twitter4j.conf.ConfigurationBuilder
的用法示例。
在下文中一共展示了ConfigurationBuilder.setOAuthConsumerKey方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getTwitter
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
private Twitter getTwitter() {
TwitterCredentials creds = readCredentials();
if (creds.getConsumerKey() == null) {
throw new RuntimeException("Incorrect Twitter client configuration: Consumer key is null");
}
if (creds.getConsumerSecret() == null) {
throw new RuntimeException("Incorrect Twitter client configuration: Consumer secret is null");
}
if (creds.getAccessSecret() == null) {
throw new RuntimeException("Incorrect Twitter client configuration: Access secret is null");
}
if (creds.getAccessToken() == null) {
throw new RuntimeException("Incorrect Twitter client configuration: Access token is null");
}
ConfigurationBuilder twitterConfig = new ConfigurationBuilder();
twitterConfig.setOAuthConsumerKey(creds.getConsumerKey());
twitterConfig.setOAuthConsumerSecret(creds.getConsumerSecret());
twitterConfig.setOAuthAccessToken(creds.getAccessToken());
twitterConfig.setOAuthAccessTokenSecret(creds.getAccessSecret());
twitterConfig.setJSONStoreEnabled(true);
return new TwitterFactory(twitterConfig.build()).getInstance();
}
示例2: configureTwitter
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
private static Twitter configureTwitter(Account account) {
final ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(Config.TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(Config.TWITTER_CONSUMER_SECRET);
builder.setOAuthAccessTokenSecret(account.tokenSecret());
builder.setOAuthAccessToken(account.token());
return new TwitterFactory(builder.build()).getInstance();
}
示例3: twitterStream
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Bean
public TwitterStream twitterStream() {
String consumerKey = environment.getRequiredProperty("consumerKey");
String consumerSecret = environment.getRequiredProperty("consumerSecret");
String accessToken = environment.getRequiredProperty("accessToken");
String accessTokenSecret = environment.getRequiredProperty("accessTokenSecret");
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumerSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(accessTokenSecret);
cb.setJSONStoreEnabled(true);
cb.setIncludeEntitiesEnabled(true);
return new TwitterStreamFactory(cb.build()).getInstance();
}
示例4: testSettingAccessToken2
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
public void testSettingAccessToken2() throws TwitterException {
// setup
builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();
// exercise & verify
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setApplicationOnlyAuthEnabled(true);
cb.setOAuthConsumerKey(browserConsumerKey);
cb.setOAuthConsumerSecret(browserConsumerSecret);
cb.setOAuth2TokenType(token.getTokenType());
cb.setOAuth2AccessToken(token.getAccessToken());
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
assertNotNull(searchTweetsRateLimit);
assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
示例5: getConfiguration
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
/**
* Builds a Twitter4J Configuration using the OAuth params.
*
* @return Configuration
*/
public Configuration getConfiguration() {
checkComplete();
ConfigurationBuilder confBuilder = new ConfigurationBuilder();
confBuilder.setOAuthConsumerKey(consumerKey);
confBuilder.setOAuthConsumerSecret(consumerSecret);
confBuilder.setOAuthAccessToken(accessToken);
confBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
if (getHttpProxyHost() != null) {
confBuilder.setHttpProxyHost(getHttpProxyHost());
}
if (getHttpProxyUser() != null) {
confBuilder.setHttpProxyHost(getHttpProxyUser());
}
if (getHttpProxyPassword() != null) {
confBuilder.setHttpProxyHost(getHttpProxyPassword());
}
if (httpProxyPort != null) {
confBuilder.setHttpProxyPort(httpProxyPort);
}
return confBuilder.build();
}
示例6: main
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setOAuthConsumerKey("P9sUs46f03m4xAJZzxt7Q");
cb.setOAuthConsumerSecret("Czw2g7QoURXz5WoLE8AbMounBiVAONktlQP1YleEy0");
cb.setOAuthAccessToken("182798423-gFyyrktqZmcrTu916G7zTkNX3pnTsB8Zc4s22dOc");
cb.setOAuthAccessTokenSecret("ITKJnDENspq5dVZIQMjTtG4NOj2ioT0QE2DkE9ZZA");
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
CStreamListener objStreamListener = new CStreamListener();
FilterQuery fq = new FilterQuery();
String [] keywords = TwitterConst.KEYWORDS;
fq.track(keywords);
twitterStream.addListener(objStreamListener);
twitterStream.filter(fq);
}
示例7: connect
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
public void connect() throws TwitterException {
initProperties();
ConfigurationBuilder config = new ConfigurationBuilder();
config.setOAuthConsumerKey(getOauthKey());
config.setOAuthConsumerSecret(getOauthSecret());
config.setOAuthAccessToken(getToken());
config.setOAuthAccessTokenSecret(getTokenSecret());
twitter4j.Twitter twitter = new TwitterFactory(config.build()).getInstance();
User user = twitter.verifyCredentials();
if (!this.userName.equals(user.getScreenName())) {
this.userName = user.getScreenName();
saveProperties(null);
}
//AccessToken accessToken = new AccessToken(getToken(), getTokenSecret());
//twitter4j.Twitter twitter = new TwitterFactory().getInstance(accessToken);
//twitter4j.Twitter twitter = new TwitterFactory().getInstance(getOauthKey(), getOauthSecret(), accessToken);
//twitter4j.Twitter twitter = new TwitterFactory().getInstance(getUsername(), getPassword());
setConnection(twitter);
}
示例8: testSettingAccessToken2
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
public void testSettingAccessToken2() throws TwitterException {
// setup
builder.setOAuthConsumerKey(browserConsumerKey).setOAuthConsumerSecret(browserConsumerSecret);
OAuth2Token token = new TwitterFactory(builder.build()).getInstance().getOAuth2Token();
// exercise & verify
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setUseSSL(true);
cb.setApplicationOnlyAuthEnabled(true);
cb.setOAuthConsumerKey(browserConsumerKey);
cb.setOAuthConsumerSecret(browserConsumerSecret);
cb.setOAuth2TokenType(token.getTokenType());
cb.setOAuth2AccessToken(token.getAccessToken());
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
Map<String, RateLimitStatus> rateLimitStatus = twitter.getRateLimitStatus("search");
RateLimitStatus searchTweetsRateLimit = rateLimitStatus.get("/search/tweets");
assertNotNull(searchTweetsRateLimit);
assertEquals(searchTweetsRateLimit.getLimit(), 450);
}
示例9: TimelineStream
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
/**
* <p>
* Creates a new {@code TimelineStream} instance with the given OAuth
* information to use for collection.
* </p>
*
* @param consumerKey
* the Twitter consumer key to use
* @param consumerSecret
* the Twitter consumer secret to use
* @param accessToken
* the Twitter access token to use
* @param accessTokenSecret
* the Twitter access token secret to use
*/
public TimelineStream(String consumerKey, String consumerSecret,
String accessToken, String accessTokenSecret) {
this.setShouldShutdown(false);
this.setShutdownWhenEmpty(false);
this.userIds = new LinkedBlockingQueue<Long>();
this.listeners = new HashSet<TimelineStreamListener>();
// get oauth -> build twitter collection object
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumerSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(accessTokenSecret);
// (timeout from original TLC code)
cb.setHttpConnectionTimeout(40000);
this.twitter = new TwitterFactory(cb.build()).getInstance();
}
示例10: verifyTwitterCredentials
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
protected boolean verifyTwitterCredentials()
{
Twitter twitter;
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey(mOAuthData.getConsumerKey());
cb.setOAuthConsumerSecret(mOAuthData.getConsumerSecret());
cb.setOAuthAccessToken(mOAuthData.getAccessToken());
cb.setOAuthAccessTokenSecret(mOAuthData.getAccessTokenSecret());
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
try {
User user = twitter.verifyCredentials();
return true;
} catch (TwitterException te) {
return false;
}
}
示例11: doInBackground
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@Override
protected Void doInBackground(Void... voids) {
ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
configurationBuilder
.setOAuthConsumerKey(getString(R.string.TWITTER_CONSUMER_KEY));
configurationBuilder
.setOAuthConsumerSecret(getString(R.string.TWITTER_CONSUMER_SECRET));
Configuration configuration = configurationBuilder.build();
twitter = new TwitterFactory(configuration).getInstance();
try {
RequestToken requestToken = twitter
.getOAuthRequestToken(getString(R.string.TWITTER_CALLBACK_URL));
launchLoginWebView(requestToken);
} catch (TwitterException e) {
e.printStackTrace();
}
return null;
}
示例12: loginTwitter
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
public void loginTwitter(){
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
Twitter twitter = factory.getInstance();
try {
requestToken = twitter.getOAuthRequestToken(TWITTER_CALLBACK_URL);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
}
示例13: loginToTwitter
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
private void loginToTwitter() {
// Check if already logged in
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(Config.TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(Config.TWITTER_CONSUMER_SECRET);
Configuration configuration = builder.build();
TwitterFactory factory = new TwitterFactory(configuration);
twitter = factory.getInstance();
try {
requestToken = twitter.getOAuthRequestToken(Config.TWITTER_CALLBACK_URL);
this.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
}
示例14: loginToTwitter
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
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.startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse(requestToken.getAuthenticationURL())));
} catch (TwitterException e) {
e.printStackTrace();
}
} else {
// user already logged into twitter
Toast.makeText(getApplicationContext(),
"Already Logged into twitter", Toast.LENGTH_LONG).show();
}
}
示例15: init
import twitter4j.conf.ConfigurationBuilder; //導入方法依賴的package包/類
@PostConstruct
public void init() {
try {
File log = new File(logFile);
File parentDir = log.getParentFile();
if (!parentDir.exists()) {
parentDir.mkdirs();
}
FileHandler fh = new FileHandler(logFile);
logger.addHandler(fh);
SimpleFormatter formatter = new SimpleFormatter();
fh.setFormatter(formatter);
File fbLog = new File(fallbackLogFile);
File fbParentDir = fbLog.getParentFile();
if (!fbParentDir.exists()) {
fbParentDir.mkdirs();
}
FileHandler fbFh = new FileHandler(fallbackLogFile);
fbLogger.addHandler(fbFh);
SimpleFormatter fbFormatter = new SimpleFormatter();
fbFh.setFormatter(fbFormatter);
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true);
cb.setTweetModeExtended(true);
cb.setOAuthConsumerKey(consumerKey);
cb.setOAuthConsumerSecret(consumeSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(acessSecret);
TwitterFactory tf = new TwitterFactory(cb.build());
twitter = tf.getInstance();
} catch (Exception e) {
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
}