本文整理汇总了Java中twitter4j.auth.Authorization类的典型用法代码示例。如果您正苦于以下问题:Java Authorization类的具体用法?Java Authorization怎么用?Java Authorization使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Authorization类属于twitter4j.auth包,在下文中一共展示了Authorization类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import twitter4j.auth.Authorization; //导入依赖的package包/类
private void run(CompositeConfiguration conf) {
// Spark conf
SparkConf sparkConf = new SparkConf().setAppName("TwitterSparkCrawler").setMaster(conf.getString("spark.master"))
.set("spark.serializer", conf.getString("spark.serializer"));
JavaStreamingContext jssc = new JavaStreamingContext(sparkConf, Durations.seconds(conf.getLong("stream.duration")));
// Twitter4J
// IMPORTANT: put keys in twitter4J.properties
Configuration twitterConf = ConfigurationContext.getInstance();
Authorization twitterAuth = AuthorizationFactory.getInstance(twitterConf);
// Create twitter stream
String[] filters = { "#Car" };
TwitterUtils.createStream(jssc, twitterAuth, filters).print();
// Start the computation
jssc.start();
jssc.awaitTermination();
}
示例2: TwitterAdsImpl
import twitter4j.auth.Authorization; //导入依赖的package包/类
TwitterAdsImpl(Configuration conf, Authorization auth) {
this.twitterAdsClient = new TwitterAdsClient(conf, auth);
this.targetingApi = new TwitterAdsTargetingApiImpl(twitterAdsClient);
this.accountApi = new TwitterAdsAccountApiImpl(twitterAdsClient);
this.lineItemApi = new TwitterAdsLineItemApiImpl(twitterAdsClient);
this.cardsApi = new TwitterAdsCardsApiImpl(twitterAdsClient);
this.fundingInstrumentApi = new TwitterAdsFundingInstrumentApiImpl(twitterAdsClient);
this.promotedApi = new TwitterAdsVideoApiImpl(twitterAdsClient);
this.tailoredAudienceApi = new TwitterAdsAudienceApiImpl(twitterAdsClient);
this.statApi = new TwitterAdsStatApiImpl(twitterAdsClient);
this.webEventApi = new TwitterAdsWebEventApiImpl(twitterAdsClient);
this.campaignApi = new TwitterAdsCampaignApiImpl(twitterAdsClient);
this.promotedTweetApi = new TwitterAdsPromotedTweetApiImpl(twitterAdsClient);
this.biddingApi = new TwitterAdsBiddingApiImpl(twitterAdsClient);
this.adsPreviewApi = new TwitterAdsPreviewApiImpl(twitterAdsClient);
this.callToActionApi = new TwitterCallToActionApiImpl(twitterAdsClient);
this.scheduledTweetApi = new TwitterScheduledTweetsApiImpl(twitterAdsClient);
}
示例3: HttpRequest
import twitter4j.auth.Authorization; //导入依赖的package包/类
/**
* @param method Specifies the HTTP method
* @param url the request to request
* @param parameters parameters
* @param requestBody requestBody
* @param authorization Authentication implementation. Currently BasicAuthentication, OAuthAuthentication and NullAuthentication are supported.
* @param requestHeaders
*/
public HttpRequest(RequestMethod method, String url, HttpParameter[] parameters, String requestBody, Authorization authorization,
Map<String, String> requestHeaders) {
this.method = method;
if (method != RequestMethod.POST && method != RequestMethod.PUT && parameters != null && parameters.length != 0) {
if (url.contains("?")) {
this.url = url + "&" + HttpParameter.encodeParameters(parameters);
} else {
this.url = url + "?" + HttpParameter.encodeParameters(parameters);
}
this.parameters = NULL_PARAMETERS;
} else {
this.url = url;
this.parameters = parameters;
}
this.requestBody = requestBody;
this.authorization = authorization;
this.requestHeaders = requestHeaders;
}
示例4: testOAuthInstance
import twitter4j.auth.Authorization; //导入依赖的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);
}
示例5: testOAuth2Instance
import twitter4j.auth.Authorization; //导入依赖的package包/类
public void testOAuth2Instance() throws Exception {
String consumerSecret = p.getProperty("browser.oauth.consumerSecret");
String consumerKey = p.getProperty("browser.oauth.consumerSecret");
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setApplicationOnlyAuthEnabled(true);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
try {
twitter.setOAuthConsumer(consumerSecret, consumerKey);
fail("should throw IllegalStateException");
} catch (IllegalStateException ignore) {
}
Authorization auth = twitter.getAuthorization();
assertTrue(auth instanceof OAuth2Authorization);
}
示例6: testOAuth2Instance
import twitter4j.auth.Authorization; //导入依赖的package包/类
public void testOAuth2Instance() throws Exception {
String consumerSecret = p.getProperty("browser.oauth.consumerSecret");
String consumerKey = p.getProperty("browser.oauth.consumerSecret");
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setApplicationOnlyAuthEnabled(true);
cb.setUseSSL(true);
Twitter twitter = new TwitterFactory(cb.build()).getInstance();
twitter.setOAuthConsumer(consumerKey, consumerSecret);
try {
twitter.setOAuthConsumer(consumerSecret, consumerKey);
fail("should throw IllegalStateException");
} catch (IllegalStateException ignore) {
}
Authorization auth = twitter.getAuthorization();
assertTrue(auth instanceof OAuth2Authorization);
}
示例7: putWithCustomHeaders
import twitter4j.auth.Authorization; //导入依赖的package包/类
public HttpResponse putWithCustomHeaders(String url, HttpParameter[] parameters, Authorization authorization,
Map<String, String> customRequestHeaders, boolean isTonUpload) throws TwitterException {
Map<String, String> headers = new HashMap<>();
if (MapUtils.isNotEmpty(requestHeaders)) {
headers.putAll(this.requestHeaders);
}
headers.putAll(customRequestHeaders);
HttpRequest req = new HttpRequest(PUT, url, parameters, null, authorization, headers);
req.setTonUploadRequest(isTonUpload);
return request(req);
}
示例8: postWithCustomHeaders
import twitter4j.auth.Authorization; //导入依赖的package包/类
public HttpResponse postWithCustomHeaders(String url, HttpParameter[] parameters, Authorization authorization,
Map<String, String> customRequestHeaders, boolean isTonUpload) throws TwitterException {
Map<String, String> headers = new HashMap<>();
if (MapUtils.isNotEmpty(requestHeaders)) {
headers.putAll(this.requestHeaders);
}
headers.putAll(customRequestHeaders);
HttpRequest req = new HttpRequest(POST, url, parameters, null, authorization, headers);
req.setTonUploadRequest(isTonUpload);
return request(req);
}
示例9: TwitterImpl
import twitter4j.auth.Authorization; //导入依赖的package包/类
public TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
TWEET_MODE = new HttpParameter("tweet_mode", conf.getTweetMode());
HttpParameter[] implicitParams = implicitParamsMap.get(conf);
String implicitParamsStr = implicitParamsStrMap.get(conf);
if (implicitParams == null) {
String includeEntities = conf.isIncludeEntitiesEnabled() ? "1" : "0";
String includeRTs = conf.isIncludeRTsEnabled() ? "1" : "0";
boolean contributorsEnabled = conf.getContributingTo() != -1L;
implicitParamsStr = "include_entities=" + includeEntities + "&include_rts=" + includeRTs +
(contributorsEnabled ? "&contributingto=" + conf.getContributingTo() : "");
implicitParamsStrMap.put(conf, implicitParamsStr);
List<HttpParameter> params = new ArrayList<HttpParameter>();
params.add(new HttpParameter("include_entities", includeEntities));
params.add(new HttpParameter("include_rts", includeRTs));
if (contributorsEnabled) {
params.add(new HttpParameter("contributingto", conf.getContributingTo()));
}
implicitParams = params.toArray(new HttpParameter[params.size()]);
implicitParamsMap.put(conf, implicitParams);
}
IMPLICIT_PARAMS = implicitParams;
IMPLICIT_PARAMS_STR = implicitParamsStr;
}
示例10: readObject
import twitter4j.auth.Authorization; //导入依赖的package包/类
private void readObject(ObjectInputStream stream)
throws IOException, ClassNotFoundException {
// http://docs.oracle.com/javase/6/docs/platform/serialization/spec/input.html#2971
stream.readFields();
conf = (Configuration) stream.readObject();
auth = (Authorization) stream.readObject();
rateLimitStatusListeners = (List<RateLimitStatusListener>) stream.readObject();
http = HttpClientFactory.getInstance(conf.getHttpClientConfiguration());
setFactory();
}
示例11: TwitterImpl
import twitter4j.auth.Authorization; //导入依赖的package包/类
TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
if (implicitParamsMap.containsKey(conf)) {
this.IMPLICIT_PARAMS = implicitParamsMap.get(conf);
this.IMPLICIT_PARAMS_STR = implicitParamsStrMap.get(conf);
} else {
String implicitParamsStr = conf.isIncludeEntitiesEnabled() ? "include_entities=" + true : "";
boolean contributorsEnabled = conf.getContributingTo() != -1L;
if (contributorsEnabled) {
if (!"".equals(implicitParamsStr)) {
implicitParamsStr += "?";
}
implicitParamsStr += "contributingto=" + conf.getContributingTo();
}
List<HttpParameter> params = new ArrayList<HttpParameter>(3);
if (conf.isIncludeEntitiesEnabled()) {
params.add(new HttpParameter("include_entities", "true"));
}
if (contributorsEnabled) {
params.add(new HttpParameter("contributingto", conf.getContributingTo()));
}
if (conf.isTrimUserEnabled()) {
params.add(new HttpParameter("trim_user", "1"));
}
if (conf.isIncludeExtAltTextEnabled()) {
params.add(new HttpParameter("include_ext_alt_text", "true"));
}
HttpParameter[] implicitParams = params.toArray(new HttpParameter[params.size()]);
// implicitParamsMap.containsKey() is evaluated in the above if clause.
// thus implicitParamsStrMap needs to be initialized first
implicitParamsStrMap.putIfAbsent(conf, implicitParamsStr);
implicitParamsMap.putIfAbsent(conf, implicitParams);
this.IMPLICIT_PARAMS = implicitParams;
this.IMPLICIT_PARAMS_STR = implicitParamsStr;
}
}
示例12: HttpRequest
import twitter4j.auth.Authorization; //导入依赖的package包/类
/**
* @param method Specifies the HTTP method
* @param url the request to request
* @param parameters parameters
* @param authorization Authentication implementation. Currently BasicAuthentication, OAuthAuthentication and NullAuthentication are supported.
* @param requestHeaders request headers
*/
public HttpRequest(RequestMethod method, String url, HttpParameter[] parameters
, Authorization authorization, Map<String, String> requestHeaders) {
this.method = method;
if (method != RequestMethod.POST && parameters != null && parameters.length != 0) {
this.url = url + "?" + HttpParameter.encodeParameters(parameters);
this.parameters = NULL_PARAMETERS;
} else {
this.url = url;
this.parameters = parameters;
}
this.authorization = authorization;
this.requestHeaders = requestHeaders;
}
示例13: TwitterImpl
import twitter4j.auth.Authorization; //导入依赖的package包/类
TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
if (implicitParamsMap.containsKey(conf)) {
this.IMPLICIT_PARAMS = implicitParamsMap.get(conf);
this.IMPLICIT_PARAMS_STR = implicitParamsStrMap.get(conf);
} else {
String implicitParamsStr = conf.isIncludeEntitiesEnabled() ? "include_entities=" + true : "";
boolean contributorsEnabled = conf.getContributingTo() != -1L;
if (contributorsEnabled) {
if (!"".equals(implicitParamsStr)) {
implicitParamsStr += "?";
}
implicitParamsStr += "contributingto=" + conf.getContributingTo();
}
List<HttpParameter> params = new ArrayList<HttpParameter>(3);
if (conf.isIncludeEntitiesEnabled()) {
params.add(new HttpParameter("include_entities", "true"));
}
if (contributorsEnabled) {
params.add(new HttpParameter("contributingto", conf.getContributingTo()));
}
if (conf.isTrimUserEnabled()) {
params.add(new HttpParameter("trim_user", "1"));
}
HttpParameter[] implicitParams = params.toArray(new HttpParameter[params.size()]);
// implicitParamsMap.containsKey() is evaluated in the above if clause.
// thus implicitParamsStrMap needs to be initialized first
implicitParamsStrMap.putIfAbsent(conf, implicitParamsStr);
implicitParamsMap.putIfAbsent(conf, implicitParams);
this.IMPLICIT_PARAMS = implicitParams;
this.IMPLICIT_PARAMS_STR = implicitParamsStr;
}
}
示例14: TwitterImpl
import twitter4j.auth.Authorization; //导入依赖的package包/类
TwitterImpl(Configuration conf, Authorization auth) {
super(conf, auth);
INCLUDE_MY_RETWEET = new HttpParameter("include_my_retweet", conf.isIncludeMyRetweetEnabled());
HttpParameter[] implicitParams = implicitParamsMap.get(conf);
String implicitParamsStr = implicitParamsStrMap.get(conf);
if (implicitParams == null) {
String includeEntities = conf.isIncludeEntitiesEnabled() ? "1" : "0";
String includeRTs = conf.isIncludeRTsEnabled() ? "1" : "0";
boolean contributorsEnabled = conf.getContributingTo() != -1L;
implicitParamsStr = "include_entities=" + includeEntities + "&include_rts=" + includeRTs
+ (contributorsEnabled ? "&contributingto=" + conf.getContributingTo() : "");
implicitParamsStrMap.put(conf, implicitParamsStr);
List<HttpParameter> params = new ArrayList<HttpParameter>(4);
params.add(new HttpParameter("include_entities", includeEntities));
params.add(new HttpParameter("include_rts", includeRTs));
if (contributorsEnabled) {
params.add(new HttpParameter("contributingto", conf.getContributingTo()));
}
if (conf.isTrimUserEnabled()) {
params.add(new HttpParameter("trim_user", "1"));
}
implicitParams = params.toArray(new HttpParameter[params.size()]);
implicitParamsMap.put(conf, implicitParams);
}
IMPLICIT_PARAMS = implicitParams;
IMPLICIT_PARAMS_STR = implicitParamsStr;
}
示例15: HttpRequest
import twitter4j.auth.Authorization; //导入依赖的package包/类
/**
* @param method Specifies the HTTP method
* @param url the request to request
* @param parameters parameters
* @param authorization Authentication implementation. Currently BasicAuthentication, OAuthAuthentication and NullAuthentication are supported.
* @param requestHeaders
*/
public HttpRequest(RequestMethod method, String url, HttpParameter[] parameters
, Authorization authorization, Map<String, String> requestHeaders) {
this.method = method;
if (method != RequestMethod.POST && parameters != null && parameters.length != 0) {
this.url = url + "?" + HttpParameter.encodeParameters(parameters);
this.parameters = NULL_PARAMETERS;
} else {
this.url = url;
this.parameters = parameters;
}
this.authorization = authorization;
this.requestHeaders = requestHeaders;
}