Search in sources :

Example 11 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class LoadGroupInfoTask method doInBackground.

@Override
protected Group doInBackground(OAuth... params) {
    if (BuildConfig.DEBUG)
        Log.d(TAG, "Starting LoadGroupInfoTask");
    OAuth oauth = params[0];
    if (oauth != null) {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Authenticated call");
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        try {
            return f.getGroupsInterface().getInfo(mGroupId);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Unauthenticated call");
        try {
            return FlickrHelper.getInstance().getGroupsInterface().getInfo(mGroupId);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    }
    return null;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 12 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class LoadGroupsTask method doInBackground.

@Override
protected Collection<Group> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        try {
            return f.getPoolsInterface().getGroups();
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        Log.e(TAG, "LoadGroupsTask requires authentication");
    }
    return null;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 13 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class LoadPhotostreamTask method doInBackground.

@Override
protected List<Photo> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(token.getOauthToken(), token.getOauthTokenSecret());
        if (BuildConfig.DEBUG)
            Log.d(TAG, "Fetching page " + mPage);
        try {
            return f.getPeopleInterface().getPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        try {
            return FlickrHelper.getInstance().getPeopleInterface().getPublicPhotos(mUser.getId(), Constants.EXTRAS, Constants.FETCH_PER_PAGE, mPage);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    }
    return null;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 14 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class FlickrHelper method getFlickrAuthed.

public Flickr getFlickrAuthed(String token, String secret) {
    Flickr f = getFlickr();
    RequestContext requestContext = RequestContext.getRequestContext();
    OAuth auth = new OAuth();
    auth.setToken(new OAuthToken(token, secret));
    requestContext.setOAuth(auth);
    return f;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) Flickr(com.googlecode.flickrjandroid.Flickr) RequestContext(com.googlecode.flickrjandroid.RequestContext) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Example 15 with OAuth

use of com.googlecode.flickrjandroid.oauth.OAuth in project glimmr by brk3.

the class OAuthUtils method loadAccessToken.

public static OAuth loadAccessToken(Context context) {
    SharedPreferences prefs = context.getSharedPreferences(Constants.PREFS_NAME, Context.MODE_PRIVATE);
    String oauthTokenString = prefs.getString(Constants.KEY_OAUTH_TOKEN, null);
    String tokenSecret = prefs.getString(Constants.KEY_TOKEN_SECRET, null);
    String userName = prefs.getString(Constants.KEY_ACCOUNT_USER_NAME, null);
    String userId = prefs.getString(Constants.KEY_ACCOUNT_USER_ID, null);
    OAuth oauth = null;
    if (oauthTokenString != null && tokenSecret != null && userName != null && userId != null) {
        oauth = new OAuth();
        OAuthToken oauthToken = new OAuthToken();
        oauth.setToken(oauthToken);
        oauthToken.setOauthToken(oauthTokenString);
        oauthToken.setOauthTokenSecret(tokenSecret);
        User user = new User();
        user.setUsername(userName);
        user.setId(userId);
        oauth.setUser(user);
    } else {
        Log.w(TAG, "No saved oauth token found");
        return null;
    }
    return oauth;
}
Also used : OAuthToken(com.googlecode.flickrjandroid.oauth.OAuthToken) User(com.googlecode.flickrjandroid.people.User) SharedPreferences(android.content.SharedPreferences) OAuth(com.googlecode.flickrjandroid.oauth.OAuth)

Aggregations

OAuth (com.googlecode.flickrjandroid.oauth.OAuth)15 OAuthToken (com.googlecode.flickrjandroid.oauth.OAuthToken)13 Flickr (com.googlecode.flickrjandroid.Flickr)12 SharedPreferences (android.content.SharedPreferences)1 RequestContext (com.googlecode.flickrjandroid.RequestContext)1 User (com.googlecode.flickrjandroid.people.User)1 SearchParameters (com.googlecode.flickrjandroid.photos.SearchParameters)1 ArrayList (java.util.ArrayList)1