本文整理汇总了Java中twitter4j.auth.OAuthAuthorization类的典型用法代码示例。如果您正苦于以下问题:Java OAuthAuthorization类的具体用法?Java OAuthAuthorization怎么用?Java OAuthAuthorization使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
OAuthAuthorization类属于twitter4j.auth包,在下文中一共展示了OAuthAuthorization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setOAuthConsumer
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
@Override
public synchronized void setOAuthConsumer(String consumerKey, String consumerSecret) {
if (null == consumerKey) {
throw new NullPointerException("consumer key is null");
}
if (null == consumerSecret) {
throw new NullPointerException("consumer secret is null");
}
if (auth instanceof NullAuthorization) {
if (conf.isApplicationOnlyAuthEnabled()) {
OAuth2Authorization oauth2 = new OAuth2Authorization(conf);
oauth2.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth2;
} else {
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = oauth;
}
} else if (auth instanceof BasicAuthorization) {
XAuthAuthorization xauth = new XAuthAuthorization((BasicAuthorization) auth);
xauth.setOAuthConsumer(consumerKey, consumerSecret);
auth = xauth;
} else if (auth instanceof OAuthAuthorization || auth instanceof OAuth2Authorization) {
throw new IllegalStateException("consumer key/secret pair already set.");
}
}
示例2: testOAuthInstance
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public void testOAuthInstance() throws Exception {
String consumerSecret;
String consumerKey;
consumerSecret = p.getProperty("browser.oauth.consumerSecret");
consumerKey = p.getProperty("browser.oauth.consumerSecret");
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
try {
twitter.setOAuthConsumer(consumerSecret, consumerKey);
fail("should throw IllegalStateException");
} catch (IllegalStateException ignore) {
}
Authorization auth = twitter.getAuthorization();
assertTrue(auth instanceof OAuthAuthorization);
}
示例3: saveTweetMarker
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
private Observable<Long> saveTweetMarker(final long tweetId) {
return Observable.create(new Observable.OnSubscribe<Long>() {
@Override
public void call(Subscriber<? super Long> subscriber) {
subscriber.onNext(
TweetMarkerUtils.save(tweetMarkerCollection(), tweetId, mAccount.screenName(),
(OAuthAuthorization) mTwitter.getAuthorization())
);
subscriber.onCompleted();
}
});
}
示例4: save
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public static long save(String collection, long lastRead, String user, OAuthAuthorization oauth) {
try {
collection = "lists." + Long.parseLong(collection);
} catch (NumberFormatException ignored) {
}
try {
final String auth = generateVerifyCredentialsAuthorizationHeader(TWITTER_VERIFY_CREDENTIALS_JSON, oauth);
JSONObject body = new JSONObject();
JSONObject collectionJson = new JSONObject();
collectionJson.put("id", lastRead);
body.put(collection, collectionJson);
MediaType JSON = MediaType.parse("application/json; charset=utf-8");
Request request = new Request.Builder()
.url(TWEETMARKER_API_URL + "?api_key=" + API_KEY + "&username=" + user)
.addHeader("X-Auth-Service-Provider", TWITTER_VERIFY_CREDENTIALS_JSON)
.addHeader("X-Verify-Credentials-Authorization", auth)
.post(RequestBody.create(JSON, body.toString()))
.build();
final Response response = createHttpClientWithoutSSL().newCall(request).execute();
if (response.isSuccessful()) return lastRead;
} catch (JSONException | IOException | KeyManagementException | NoSuchAlgorithmException e) {
Timber.i(e, "");
}
return -1;
}
示例5: getInstance
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
/**
* Returns a OAuth Authenticated instance.<br>
* consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.<br>
* Unlike {@link Twitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance.
*
* @param accessToken access token
* @return an instance
* @since Twitter4J 2.1.9
*/
public Twitter getInstance(AccessToken accessToken) {
String consumerKey = conf.getOAuthConsumerKey();
String consumerSecret = conf.getOAuthConsumerSecret();
if (null == consumerKey && null == consumerSecret) {
throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
}
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthAccessToken(accessToken);
return getInstance(oauth);
}
示例6: connect
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public void connect() {
ApiKeys keys = getBot().getApiKeys();
if (!isConnected()) {
Configuration configuration = new ConfigurationBuilder().setOAuthAccessToken(keys.getAccessToken()).setOAuthAccessTokenSecret(keys.getAccessTokenSecret()).setOAuthConsumerKey(keys.getConsumerKey()).setOAuthConsumerSecret(keys.getConsumerSecret()).build();
OAuthAuthorization auth = new OAuthAuthorization(configuration);
TwitterStreamFactory streamFactory = new TwitterStreamFactory(configuration);
ImageUploadFactory uploadFactory = new ImageUploadFactory(configuration);
this.streamer = streamFactory.getInstance(auth);
this.uploader = uploadFactory.getInstance(auth);
}
}
示例7: connectTwitter
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
private void connectTwitter() {
tracker.send(new HitBuilders.EventBuilder().setCategory("account").setAction("connect").build());
new AsyncTask<Void, Void, Void>() {
RequestToken getRequestToken() throws TwitterException {
OAuthAuthorization oAuthAuthorization = new OAuthAuthorization(
new PropertyConfiguration(getResources().openRawResource(R.raw.twitter4j)));
requestToken = oAuthAuthorization.getOAuthRequestToken("wearapps://twitter.auth");
// temporary data, used again when swapping the oauth token with access token
settings.edit().putString(REQUEST_TOKEN, requestToken.getToken()).commit();
settings.edit().putString(REQUEST_TOKEN_SECRET, requestToken.getTokenSecret()).commit();
return requestToken;
}
@Override
protected Void doInBackground(Void... params) {
try {
requestToken = getRequestToken();
} catch (TwitterException e) {
e.printStackTrace();
}
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(requestToken.getAuthorizationURL()));
startActivity(intent);
finish();
return null;
}
}.execute();
}
示例8: AbsUploadProviderImpl
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public AbsUploadProviderImpl(final Configuration confOrig, final AccountWithCredentials account) {
this.account = account;
final ConfigurationBuilder cb = new ConfigurationBuilder(confOrig);
cb.setOAuthConsumerKey(account.consumer_key);
cb.setOAuthConsumerSecret(account.consumer_secret);
cb.setRestBaseURL(account.rest_base_url);
cb.setOAuthBaseURL(account.oauth_base_url);
cb.setSigningRestBaseURL(account.signing_rest_base_url);
cb.setSigningOAuthBaseURL(account.signing_oauth_base_url);
conf = cb.build();
oauth = new OAuthAuthorization(conf);
oauth.setOAuthAccessToken(new AccessToken(account.oauth_token, account.oauth_token_secret));
oauth.setOAuthRealm("https://api.twitter.com/");
client = new HttpClientWrapper(confOrig);
}
示例9: getInstance
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
/**
* Returns a OAuth Authenticated instance.<br>
* consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.<br>
* Unlike {@link AsyncTwitter#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance.
*
* @param accessToken access token
* @return an instance
*/
public AsyncTwitter getInstance(AccessToken accessToken) {
String consumerKey = conf.getOAuthConsumerKey();
String consumerSecret = conf.getOAuthConsumerSecret();
if (null == consumerKey && null == consumerSecret) {
throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
}
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthConsumer(consumerKey, consumerSecret);
oauth.setOAuthAccessToken(accessToken);
return new AsyncTwitterImpl(conf, oauth);
}
示例10: getInstance
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
/**
* Returns a OAuth Authenticated instance.<br>
* consumer key and consumer Secret must be provided by twitter4j.properties, or system properties.
* Unlike {@link TwitterStream#setOAuthAccessToken(twitter4j.auth.AccessToken)}, this factory method potentially returns a cached instance.
*
* @param accessToken access token
* @return an instance
*/
public TwitterStream getInstance(AccessToken accessToken) {
String consumerKey = conf.getOAuthConsumerKey();
String consumerSecret = conf.getOAuthConsumerSecret();
if (null == consumerKey && null == consumerSecret) {
throw new IllegalStateException("Consumer key and Consumer secret not supplied.");
}
OAuthAuthorization oauth = new OAuthAuthorization(conf);
oauth.setOAuthAccessToken(accessToken);
return getInstance(conf, oauth);
}
示例11: getInstance
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
/**
* Returns an ImageUpload instance associated with the specified media provider
*
* @param mediaProvider media provider
* @param authorization authorization
* @return ImageUpload
* @since Twitter4J 2.1.11
*/
public ImageUpload getInstance(MediaProvider mediaProvider, Authorization authorization) {
if (!(authorization instanceof OAuthAuthorization)) {
throw new IllegalArgumentException("OAuth authorization is required.");
}
OAuthAuthorization oauth = (OAuthAuthorization) authorization;
if (mediaProvider == TWITTER) {
return new TwitterUpload(conf, oauth);
} else if (mediaProvider == IMG_LY) {
return new ImgLyUpload(conf, oauth);
} else if (mediaProvider == PLIXI) {
return new PlixiUpload(conf, apiKey, oauth);
} else if (mediaProvider == LOCKERZ) {
return new PlixiUpload(conf, apiKey, oauth);
} else if (mediaProvider == TWIPPLE) {
return new TwippleUpload(conf, oauth);
} else if (mediaProvider == TWITGOO) {
return new TwitgooUpload(conf, oauth);
} else if (mediaProvider == TWITPIC) {
return new TwitpicUpload(conf, apiKey, oauth);
} else if (mediaProvider == YFROG) {
return new YFrogUpload(conf, oauth);
} else if (mediaProvider == MOBYPICTURE) {
return new MobypictureUpload(conf, apiKey, oauth);
} else if (mediaProvider == POSTEROUS) {
return new PosterousUpload(conf, oauth);
} else {
throw new AssertionError("Unknown provider");
}
}
示例12: startOAuth
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
private void startOAuth() {
new Thread() {
public void run() {
ConfigurationBuilder cbuilder = new ConfigurationBuilder();
cbuilder.setOAuthConsumerKey(Settings.CONSUMER_KEY);
cbuilder.setOAuthConsumerSecret(Settings.CONSUMER_SECRET);
Configuration conf = cbuilder.build();
mOauth = new OAuthAuthorization(conf);
String authUrl = null;
try {
RequestToken requestToken = mOauth
.getOAuthRequestToken(null);
authUrl = requestToken.getAuthorizationURL();
} catch (Exception e) {
e.printStackTrace();
return;
}
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(authUrl));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
};
}.start();
setContentView(R.layout.login);
findViewById(R.id.login).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// ピンコード処理を書く
EditText editText = (EditText) findViewById(R.id.pincode);
getOAuthAccessToken(editText.getText().toString());
}
});
}
开发者ID:android-opensource-library-56,项目名称:android-opensource-library-56,代码行数:35,代码来源:Twitter4jSampleActivity.java
示例13: getInstanceFor
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public static Twitter getInstanceFor(String accessToken, String accessTokenSecret){
ConfigurationBuilder cb= new ConfigurationBuilder();
cb.setOAuthConsumerKey(Config.twConsumerKey);
cb.setOAuthConsumerSecret(Config.twConsumerSecret);
cb.setOAuthAccessToken(accessToken);
cb.setOAuthAccessTokenSecret(accessTokenSecret);
Twitter twitter = tf.getInstance(new OAuthAuthorization(cb.build()));
return twitter;
}
示例14: getAccessTokenFor
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public static AccessToken getAccessTokenFor(RequestToken requestToken,
String oauthVerifier) throws TwitterException {
ConfigurationBuilder cb= new ConfigurationBuilder();
cb.setOAuthConsumerKey(Config.twConsumerKey);
cb.setOAuthConsumerSecret(Config.twConsumerSecret);
Twitter twitter = tf.getInstance(new OAuthAuthorization(cb.build()));
AccessToken accessToken;
if(oauthVerifier!=null)
accessToken = twitter.getOAuthAccessToken(requestToken, oauthVerifier);
else
accessToken = twitter.getOAuthAccessToken(requestToken);
return accessToken;
}
示例15: getRequestToken
import twitter4j.auth.OAuthAuthorization; //导入依赖的package包/类
public static RequestToken getRequestToken() throws TwitterException {
ConfigurationBuilder cb= new ConfigurationBuilder();
cb.setOAuthConsumerKey(Config.twConsumerKey);
cb.setOAuthConsumerSecret(Config.twConsumerSecret);
Twitter twitter = tf.getInstance(new OAuthAuthorization(cb.build()));
RequestToken requestToken = twitter.getOAuthRequestToken();
return requestToken;
}