public OAuth getOAuthToken() { // Restore preferences SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE); String oauthTokenString = settings.getString(KEY_OAUTH_TOKEN, null); String tokenSecret = settings.getString(KEY_TOKEN_SECRET, null); if (oauthTokenString == null && tokenSecret == null) { logger.warn("No oauth token retrieved"); // $NON-NLS-1$ return null; } OAuth oauth = new OAuth(); String userName = settings.getString(KEY_USER_NAME, null); String userId = settings.getString(KEY_USER_ID, null); if (userId != null) { User user = new User(); user.setUsername(userName); user.setId(userId); oauth.setUser(user); } OAuthToken oauthToken = new OAuthToken(); oauth.setToken(oauthToken); oauthToken.setOauthToken(oauthTokenString); oauthToken.setOauthTokenSecret(tokenSecret); logger.debug( "Retrieved token from preference store: oauth token={}, and token secret={}", oauthTokenString, tokenSecret); //$NON-NLS-1$ return oauth; }
private List<Photo> getUserPhotos() throws Exception { OAuthToken token = mOAuth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); return f.getPeopleInterface() .getPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, PAGE); }
public static OAuth getOAuthToken() { String oauthTokenString = CacheManager.getStringCacheData(KEY_OAUTH_TOKEN); String tokenSecret = CacheManager.getStringCacheData(KEY_TOKEN_SECRET); if (StringUtils.isNull(oauthTokenString) && StringUtils.isNull(tokenSecret)) { return null; } OAuth oauth = new OAuth(); String userName = CacheManager.getStringCacheData(KEY_USER_NAME); String userId = CacheManager.getStringCacheData(KEY_USER_ID); if (StringUtils.isNotNull(userId)) { User user = new User(); user.setUsername(userName); user.setId(userId); oauth.setUser(user); } OAuthToken oauthToken = new OAuthToken(); oauth.setToken(oauthToken); oauthToken.setOauthToken(oauthTokenString); oauthToken.setOauthTokenSecret(tokenSecret); return oauth; }
private List<Photo> getFavoritePhotos() throws Exception { OAuthToken token = mOAuth.getToken(); Flickr f = FlickrHelper.getInstance() .getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret()); Date minFavDate = null; Date maxFavDate = null; return f.getFavoritesInterface() .getList( mUser.getId(), minFavDate, maxFavDate, Constants.FETCH_PER_PAGE, PAGE, Constants.EXTRAS); }
public void onOAuthDone(OAuth result) { if (result == null) { Toast.makeText( this, "Authorization failed", //$NON-NLS-1$ Toast.LENGTH_LONG) .show(); } else { User user = result.getUser(); OAuthToken token = result.getToken(); if (user == null || user.getId() == null || token == null || token.getOauthToken() == null || token.getOauthTokenSecret() == null) { Toast.makeText( this, "Authorization failed", //$NON-NLS-1$ Toast.LENGTH_LONG) .show(); return; } String message = String.format( Locale.US, "Authorization Succeed: user=%s, userId=%s, oauthToken=%s, tokenSecret=%s", //$NON-NLS-1$ user.getUsername(), user.getId(), token.getOauthToken(), token.getOauthTokenSecret()); Toast.makeText(this, message, Toast.LENGTH_LONG).show(); saveOAuthToken( user.getUsername(), user.getId(), token.getOauthToken(), token.getOauthTokenSecret()); load(result); } }
public void setUser(User user) { textUserTitle.setText(user.getUsername()); textUserName.setText(user.getRealName()); textUserId.setText(user.getId()); }