use of twitter4j.TwitterFactory in project twicalico by moko256.
the class GlobalApplication method getTwitterInstance.
@NonNull
public Twitter getTwitterInstance(@NonNull AccessToken accessToken) {
Twitter t;
Configuration conf;
if (accessToken.getType() == Type.TWITTER) {
conf = new ConfigurationBuilder().setTweetModeExtended(true).setOAuthConsumerKey(BuildConfig.CONSUMER_KEY).setOAuthConsumerSecret(BuildConfig.CONSUMER_SECRET).setOAuthAccessToken(accessToken.getToken()).setOAuthAccessTokenSecret(accessToken.getTokenSecret()).build();
t = twitterCache.get(conf);
if (t == null) {
t = new TwitterFactory(conf).getInstance();
twitterCache.put(conf, t);
}
} else {
conf = new ConfigurationBuilder().setOAuthAccessToken(accessToken.getToken()).setRestBaseURL(accessToken.getUrl()).build();
t = twitterCache.get(conf);
if (t == null) {
t = new MastodonTwitterImpl(conf, accessToken.getUserId(), getOkHttpClient(conf.getHttpClientConfiguration()).newBuilder());
twitterCache.put(conf, t);
}
}
return t;
}
use of twitter4j.TwitterFactory in project AndroidSDK-RecipeBook by gabu.
the class Auth method onOKButton.
// OKボタンが押されたら呼び出される
public void onOKButton(View view) {
// 入力されたユーザIDとパスワードを取得
String userID = ((EditText) findViewById(R.id.user_id)).getText().toString();
String password = ((EditText) findViewById(R.id.password)).getText().toString();
// とりあえずユーザIDとパスワードでTwitterインスタンスを生成
Twitter twitter = new TwitterFactory().getInstance(userID, password);
try {
// AccessTokenを取得
AccessToken accessToken = twitter.getOAuthAccessToken();
// tokenとtokenSecretを取得
String token = accessToken.getToken();
String tokenSecret = accessToken.getTokenSecret();
// プリファレンスのEditorを取得
Editor e = getSharedPreferences(Recipe102.PREF_NAME, MODE_PRIVATE).edit();
// tokenとtokenSecretを書き込んで
e.putString(Recipe102.PREF_KEY_TOKEN, token);
e.putString(Recipe102.PREF_KEY_TOKEN_SECRET, tokenSecret);
// 保存!
e.commit();
// Authアクティビティを終了
finish();
} catch (TwitterException e) {
e.printStackTrace();
Toast.makeText(getApplicationContext(), "ユーザIDかパスワードが間違っています。", Toast.LENGTH_SHORT).show();
}
}
use of twitter4j.TwitterFactory in project AndroidSDK-RecipeBook by gabu.
the class Recipe102 method onResume.
public void onResume() {
super.onResume();
// プリファレンスを取得
SharedPreferences sp = getSharedPreferences(PREF_NAME, MODE_PRIVATE);
// tokenとtokenSecretを取得
String token = sp.getString(PREF_KEY_TOKEN, "");
String tokenSecret = sp.getString(PREF_KEY_TOKEN_SECRET, "");
// 値がなければAuthアクティビティを起動
if ("".equals(token) || "".equals(tokenSecret)) {
Intent intent = new Intent(this, Auth.class);
startActivity(intent);
}
// twitter4jのConfigurationを取得
Configuration conf = ConfigurationContext.getInstance();
// AccessTokenを生成
AccessToken accessToken = new AccessToken(token, tokenSecret);
// OAuthAuthorizationを生成
Authorization auth = new OAuthAuthorization(conf, conf.getOAuthConsumerKey(), conf.getOAuthConsumerSecret(), accessToken);
// OAuthAuthorizationを使ってTwitterインスタンスを生成
Twitter twitter = new TwitterFactory().getInstance(auth);
try {
// とりあえずテストのためTLをログ出力
ResponseList<Status> statuses = twitter.getHomeTimeline();
for (Status status : statuses) {
Log.d(TAG, status.getUser().getName() + ":" + status.getText());
}
} catch (TwitterException e) {
e.printStackTrace();
}
}
use of twitter4j.TwitterFactory in project Talon-for-Twitter by klinker24.
the class Utils method getTwitter.
public static Twitter getTwitter(Context context, AppSettings settings) {
if (settings == null) {
settings = AppSettings.getInstance(context);
}
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true).setOAuthConsumerKey(AppSettings.TWITTER_CONSUMER_KEY).setOAuthConsumerSecret(AppSettings.TWITTER_CONSUMER_SECRET).setOAuthAccessToken(settings.authenticationToken).setOAuthAccessTokenSecret(settings.authenticationTokenSecret);
cb.setTweetModeExtended(true);
TwitterFactory tf = new TwitterFactory(cb.build());
return tf.getInstance();
}
use of twitter4j.TwitterFactory in project twitter-2-weibo by rjyo.
the class AuthServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpServletRouter r = new HttpServletRouter(request);
r.setPattern("/:type");
response.setContentType("text/plain");
PrintWriter writer = response.getWriter();
String serverPath = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath();
HttpSession session = request.getSession();
if (r.is(":type", "weibo")) {
try {
Oauth oauth = new Oauth();
String redirectUrl = oauth.authorize("code");
response.setStatus(302);
response.setHeader("Location", redirectUrl);
log.info("Redirecting Weibo...");
} catch (WeiboException e) {
log.error(e);
}
} else if (r.is(":type", "twitter")) {
log.info("hello world~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
try {
TwitterFactory factory = new TwitterFactory();
Twitter t = factory.getInstance();
twitter4j.auth.RequestToken requestToken = t.getOAuthRequestToken(serverPath + "/callback/twitter");
response.setStatus(302);
log.info(requestToken.getAuthenticationURL());
response.setHeader("Location", requestToken.getAuthenticationURL());
session.setAttribute(Keys.SESSION_REQUEST_TOKEN, requestToken);
log.info("Redirecting Twitter...");
} catch (TwitterException e) {
log.error(e);
}
writer.close();
} else {
response.setStatus(200);
writer.println("Wrong parameter, not working!");
writer.close();
}
}
Aggregations