本文整理汇总了Java中twitter4j.auth.AccessToken类的典型用法代码示例。如果您正苦于以下问题:Java AccessToken类的具体用法?Java AccessToken怎么用?Java AccessToken使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AccessToken类属于twitter4j.auth包,在下文中一共展示了AccessToken类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTwitterOAuthTokenAndLogin
import twitter4j.auth.AccessToken; //导入依赖的package包/类
private void getTwitterOAuthTokenAndLogin(final RequestToken requestToken, final String oauthVerifier) {
// once a user authorizes the application, get the auth token and return to the MainActivity
new AsyncTask<Void, Void, AccessToken>() {
@Override
protected AccessToken doInBackground(Void... params) {
AccessToken accessToken = null;
try {
accessToken = mTwitter.getOAuthAccessToken(requestToken, oauthVerifier);
} catch (TwitterException te) {
Log.e(TAG, te.toString());
}
return accessToken;
}
@Override
protected void onPostExecute(AccessToken token) {
Intent resultIntent = new Intent();
resultIntent.putExtra("oauth_token", token.getToken());
resultIntent.putExtra("oauth_token_secret", token.getTokenSecret());
resultIntent.putExtra("user_id", token.getUserId() + "");
setResult(MainActivity.RC_TWITTER_LOGIN, resultIntent);
finish();
}
}.execute();
}
示例2: printAccessToken
import twitter4j.auth.AccessToken; //导入依赖的package包/类
void printAccessToken() {
try {
TwitterCredentials creds = TwitterFeed.readCredentials();
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(creds.getConsumerKey(), creds.getConsumerSecret());
RequestToken requestToken = twitter.getOAuthRequestToken();
System.out.println("Authorization URL: \n" + requestToken.getAuthorizationURL());
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Hit above Authorization URL and Input PIN here: ");
String pin = br.readLine();
AccessToken accessToken = twitter.getOAuthAccessToken(requestToken, pin);
System.out.println("Access Token: " + accessToken.getToken());
System.out.println("Access Token Secret: " + accessToken.getTokenSecret());
} catch (TwitterException | IOException ex) {
throw new RuntimeException(ex);
}
}
示例3: main
import twitter4j.auth.AccessToken; //导入依赖的package包/类
public static void main(String[] args) {
try {
Twitter twitter = new TwitterFactory().getInstance();
twitter.setOAuthConsumer(consumerKeyStr, consumerSecretStr);
AccessToken accessToken = new AccessToken(accessTokenStr,
accessTokenSecretStr);
twitter.setOAuthAccessToken(accessToken);
twitter.updateStatus("Post using Twitter4J");
System.out.println("Successfully updated the status in Twitter.");
} catch (TwitterException te) {
te.printStackTrace();
}
}
示例4: configure
import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
public void configure(Context context) {
String consumerKey = context.getString("consumerKey");
String consumerSecret = context.getString("consumerSecret");
String accessToken = context.getString("accessToken");
String accessTokenSecret = context.getString("accessTokenSecret");
twitterStream = new TwitterStreamFactory().getInstance();
twitterStream.setOAuthConsumer(consumerKey, consumerSecret);
twitterStream.setOAuthAccessToken(new AccessToken(accessToken,
accessTokenSecret));
twitterStream.addListener(this);
avroSchema = createAvroSchema();
dataFileWriter = new DataFileWriter<GenericRecord>(
new GenericDatumWriter<GenericRecord>(avroSchema));
maxBatchSize = context.getInteger("maxBatchSize", maxBatchSize);
maxBatchDurationMillis = context.getInteger("maxBatchDurationMillis",
maxBatchDurationMillis);
}
示例5: add
import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Observable<Account> add(final AccessToken accessToken) {
ContentValues values = new ContentValues();
values.put(AccountContract.TOKEN, accessToken.getToken());
values.put(AccountContract.TOKEN_SECRET, accessToken.getTokenSecret());
values.put(AccountContract.SCREEN_NAME, accessToken.getScreenName());
values.put(AccountContract.USER_ID, accessToken.getUserId());
return mSqlBriteContentProvider
.insert(AccountContract.CONTENT_URI, values)
.flatMap(new Func1<Uri, Observable<SqlBriteContentProvider.Query>>() {
@Override
public Observable<SqlBriteContentProvider.Query> call(Uri uri) {
return mSqlBriteContentProvider
.query(uri, AccountContract.PROJECTION,
null, null, null, false);
}
})
.map(MapFunctions.ACCOUNT)
.take(1);
}
示例6: registerPinCode
import twitter4j.auth.AccessToken; //导入依赖的package包/类
private void registerPinCode(final RequestToken requestToken) {
if (this.pinIsValid) {
final Optional<AccessToken> success = this.twitterHandler.registerAccessToken(
requestToken,
this.pinCodeField.getText()
);
if (success.isPresent()) {
final AccessToken token = success.get();
this.loginButton.setVisible(false);
this.loginLabel.setText(
String.format(
"Successfully logged in account @%s!",
token.getScreenName())
);
} else {
ExceptionHandler.displayExceptionPane(
"Authentication Error",
"Could not authenticate you!",
new Exception("No token could be used.")
);
}
this.stageManager.getSingle(Views.LOGIN_VIEW).peek(Stages::scheduleHiding);
}
}
示例7: doInBackground
import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
protected AccessToken doInBackground(String... codes) {
AccessToken accessToken = null;
if (codes != null && codes.length > 0) {
String code = codes[0];
TwitterClient twitterClient = TwitterClient.instance();
try {
accessToken = twitterClient.getAcccessToken(twitterClient.getRequestToken(), code);
} catch (TwitterException e) {
e.printStackTrace();
}
twitterClient.authenticateUser(accessToken.getToken(), accessToken.getTokenSecret());
}
return accessToken;
}
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:TwitterPreferencesFragment.java
示例8: getTwitter
import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Twitter getTwitter() throws TwitterException, IOException
{
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_SECRET)
.setOAuthAccessToken(ACCESS_TOKEN)
.setOAuthAccessTokenSecret(ACCESS_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN, ACCESS_SECRET));
return twitter;
}
示例9: getTwitter
import twitter4j.auth.AccessToken; //导入依赖的package包/类
public Twitter getTwitter() throws TwitterException, IOException
{
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setDebugEnabled(true)
.setOAuthConsumerKey(CONSUMER_KEY)
.setOAuthConsumerSecret(CONSUMER_KEY_SECRET);
TwitterFactory tf = new TwitterFactory(cb.build());
Twitter twitter = tf.getInstance();
twitter.setOAuthAccessToken(new AccessToken(ACCESS_TOKEN,
ACCESS_TOKEN_SECRET));
return twitter;
}
示例10: checkID
import twitter4j.auth.AccessToken; //导入依赖的package包/类
private static void checkID() throws TwitterException {
twitter = TwitterFactory.getSingleton();
twitter.setOAuthConsumer("", "");
requestToken = twitter.getOAuthRequestToken();
if(Storage.getData(Connection.TOKEN) == null) {
Ressources.frame.setPanel(new ConnectionPanel(Text.PIN));
//Open web browser to access PIN code
new Thread() {
@Override
public void run() {
if(!Infonet.open(requestToken.getAuthorizationURL(), true)) {
JOptionPane.showMessageDialog(null, Storage.tra("urlError"), Storage.tra("error"), JOptionPane.ERROR_MESSAGE);
}
}
}.start();
} else {
accessToken = new AccessToken(Storage.getData(Connection.TOKEN), Storage.getData(Connection.TOKEN_SECRET));
Main.connect();
}
}
示例11: connect
import twitter4j.auth.AccessToken; //导入依赖的package包/类
/**
* Authenticates when there is no twitter instance or authorization.
* If the access token had already been configured it catches the exception, logs
* and continue with the flow.
*
* @throws Exception
*/
private void connect() throws Exception {
log.info("Authenticate Tweet Harvester.");
if (twitter != null && twitter.getAuthorization().isEnabled()) {
log.warning("Already connected to twitter.");
return;
}
try {
twitter = TwitterFactory.getSingleton();
AccessToken accessToken = new AccessToken(oauthAccessToken, oauthAccessTokenSecret);
twitter.setOAuthConsumer(consumerKey, consumerSecret);
twitter.setOAuthAccessToken(accessToken);
log.info("Tweet Harvester authenticated with success.");
} catch (IllegalStateException e) {
log.error("Something went wrong or Already authenticated: " + e.getMessage());
}
}
示例12: saveVariable
import twitter4j.auth.AccessToken; //导入依赖的package包/类
@Override
public boolean saveVariable(String jsonString) {
if(jsonString.isEmpty() || jsonString == null){ throw new IllegalArgumentException(); }
JsonObject source = jm.createJsonObject(jsonString);
if(!source.has("WhiteEggPlayer")){ return false; }
JsonObject json = source.getAsJsonObject("WhiteEggPlayer");
JsonObject player = json.getAsJsonObject("player");
if(json.get("twitter").isJsonObject()){
JsonObject tw = json.getAsJsonObject("twitter");
AccessToken token = new AccessToken(tw.get("accesstoken").getAsString(), tw.get("accesstokensecret").getAsString());
this.getTwitterManager().setAccessToken(token);
}
this.setRank(player);
this.setToggle(player);
AltAccount.parser(player.toString());
return true;
}
示例13: start
import twitter4j.auth.AccessToken; //导入依赖的package包/类
private static void start() {
if (!Twitter.isEnabled) {
return;
}
Twitter.client = createClient();
AccessToken accessToken = getAccessToken();
if (accessToken != null) {
Twitter.client.setOAuthAccessToken(accessToken);
logger.info("TwitterAction has been successfully authenticated > awaiting your Tweets!");
} else {
logger.info("Twitter authentication failed. Please use OSGi "
+ "console to restart the org.openhab.io.net-Bundle and re-initiate the authorization process!");
}
}
示例14: doGet
import twitter4j.auth.AccessToken; //导入依赖的package包/类
/**
* This method handles the Twitter OAuth callback and sets the twtoken cookie.
*
* @param req the http request
* @param resp the http response
* @throws ServletException if an error occurred during access
* @throws IOException if an error occurred during access
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
if (req.getParameter("denied") == null) {
Twitter twitter = (Twitter) req.getSession().getAttribute("twitter");
RequestToken requestToken = (RequestToken) req.getSession().getAttribute("requestToken");
String verifier = req.getParameter("oauth_verifier");
try {
AccessToken token = twitter.getOAuthAccessToken(requestToken, verifier);
req.getSession().removeAttribute("requestToken");
Cookie tokenCookie = new Cookie("twtoken", Base64.getEncoder().encodeToString(
(token.getToken() + " - " + token.getTokenSecret()).getBytes()));
tokenCookie.setMaxAge(-1);
tokenCookie.setHttpOnly(true);
resp.addCookie(tokenCookie);
} catch (TwitterException e) {
// Redirect to landing page
}
}
resp.sendRedirect(Constants.TWITTER);
}
示例15: signinCallback
import twitter4j.auth.AccessToken; //导入依赖的package包/类
@RequestMapping(value = "/signin/callback", method = RequestMethod.GET)
public RedirectView signinCallback(@RequestParam("oauth_verifier") final String verifier,
final HttpServletRequest request) throws WTFDYUMException {
final RequestToken requestToken = (RequestToken) request.getSession().getAttribute(SESSION_REQUEST_TOKEN);
request.getSession().removeAttribute(SESSION_REQUEST_TOKEN);
final AccessToken accessToken = twitterService.completeSignin(requestToken, verifier);
if (principalService.get(accessToken.getUserId()) == null) {
userService.addEvent(accessToken.getUserId(), new Event(EventType.REGISTRATION, null));
}
final Principal user = new Principal(accessToken.getUserId(), accessToken.getToken(), accessToken.getTokenSecret());
principalService.saveUpdate(user);
authenticationService.authenticate(user);
return new RedirectView("/user", true);
}