当前位置: 首页>>代码示例>>Java>>正文


Java OAuthAuthorization类代码示例

本文整理汇总了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.");
    }
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:27,代码来源:TwitterBaseImpl.java

示例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);
}
 
开发者ID:DiscourseDB,项目名称:discoursedb-core,代码行数:19,代码来源:AuthorizationTest.java

示例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();
        }
    });
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:13,代码来源:TimelineModel.java

示例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;
}
 
开发者ID:mecid,项目名称:robird-reborn,代码行数:33,代码来源:TweetMarkerUtils.java

示例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);
}
 
开发者ID:sprinklr-inc,项目名称:twitter4j-ads,代码行数:20,代码来源:TwitterFactory.java

示例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);
	}
}
 
开发者ID:BloodShura,项目名称:MPSBot,代码行数:14,代码来源:ConnectedBot.java

示例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();
}
 
开发者ID:glanceable,项目名称:GlanceTweet,代码行数:29,代码来源:MainActivity.java

示例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);
}
 
开发者ID:mariotaku,项目名称:twidere.extension.mediauploader,代码行数:16,代码来源:AbsUploadProviderImpl.java

示例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);
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:20,代码来源:AsyncTwitterFactory.java

示例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);
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:19,代码来源:TwitterStreamFactory.java

示例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");
    }
}
 
开发者ID:SamKnows,项目名称:skandroid-core,代码行数:38,代码来源:ImageUploadFactory.java

示例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;
}
 
开发者ID:cansin,项目名称:chitterim,代码行数:10,代码来源:TwitterAPI.java

示例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;
}
 
开发者ID:cansin,项目名称:chitterim,代码行数:14,代码来源:TwitterAPI.java

示例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;
}
 
开发者ID:cansin,项目名称:chitterim,代码行数:9,代码来源:TwitterAPI.java


注:本文中的twitter4j.auth.OAuthAuthorization类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。