com.googlecode.flickrjandroid.Flickr Java Examples

The following examples show how to use com.googlecode.flickrjandroid.Flickr. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GetAccessTokenTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
protected OAuth doInBackground(String... params) {
    String oauthToken = params[0];
    String oauthTokenSecret = params[1];
    String verifier = params[2];

    Flickr f = FlickrHelper.getInstance().getFlickr();
    OAuthInterface oauthApi = f.getOAuthInterface();
    try {
        return oauthApi.getAccessToken(oauthToken, oauthTokenSecret,
                verifier);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #2
Source File: AddCommentTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        try {
            Flickr f = FlickrHelper.getInstance().getFlickrAuthed(
                    token.getOauthToken(), token.getOauthTokenSecret());
            return f.getCommentsInterface().addComment(mPhoto.getId(),
                    mCommentText);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        Log.e(TAG, "AddCommentTask requires authentication");
    }
    return null;
}
 
Example #3
Source File: GetRequestToken.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
protected String doInBackground(Void... params) {
    try {
        Flickr f = FlickrHelper.getInstance().getFlickr();

        OAuthToken oauthToken = f.getOAuthInterface().getRequestToken(
                mOAuthCallbackUri.toString());
        saveRequestToken(oauthToken.getOauthTokenSecret());

        URL oauthUrl = f.getOAuthInterface().buildAuthenticationUrl(
                Permission.WRITE, oauthToken);

        return oauthUrl.toString();
    } catch (Exception e) {
        e.printStackTrace();
        mException = e;
    }
    return null;
}
 
Example #4
Source File: LoadContactsPhotosTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@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());
        try {
            return f.getPhotosInterface().getContactsPhotos(
                    Constants.FETCH_PER_PAGE, Constants.EXTRAS,
                    false, false, false, mPage,
                    Constants.FETCH_PER_PAGE);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        Log.e(TAG, "LoadContactsPhotosTask requires authentication");
    }
    return null;
}
 
Example #5
Source File: LoadGroupsTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #6
Source File: SetFavoriteTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
protected Exception doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        Flickr f = FlickrHelper.getInstance().getFlickrAuthed(
                token.getOauthToken(), token.getOauthTokenSecret());
        try {
            if (mPhoto.isFavorite()) {
                f.getFavoritesInterface().remove(mPhoto.getId());
            } else {
                f.getFavoritesInterface().add(mPhoto.getId());
            }
        } catch (Exception e) {
            e.printStackTrace();
            return e;
        }
    } else {
        Log.e(TAG, "SetFavoriteTask requires authentication");
    }
    return null;
}
 
Example #7
Source File: LoadFlickrActivityTask.java    From glimmr with Apache License 2.0 6 votes vote down vote up
@Override
protected List<Item> doInBackground(OAuth... params) {
    OAuth oauth = params[0];
    if (oauth != null) {
        OAuthToken token = oauth.getToken();
        try {
            Flickr f = FlickrHelper.getInstance().getFlickrAuthed(
                    token.getOauthToken(), token.getOauthTokenSecret());
            String timeFrame = "100d";
            int page = 1;
            return f.getActivityInterface().userPhotos(
                    Constants.FETCH_PER_PAGE, page, timeFrame);
        } catch (Exception e) {
            e.printStackTrace();
            mException = e;
        }
    } else {
        Log.e(TAG, "LoadFlickrActivityTask requires authentication");
    }
    return null;
}
 
Example #8
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public PhotosetsInterface getPhotosetsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getPhotosetsInterface();
    } else {
        return null;
    }
}
 
Example #9
Source File: FlickrApi.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
public static Flickr get() {
	if (auth == null) {
		updateOauth();
	}
	if (RequestContext.getRequestContext().getOAuth() != auth) {
		RequestContext.getRequestContext().setOAuth(auth);
	}
	return flickr;
}
 
Example #10
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public CommentsInterface getCommentsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getCommentsInterface();
    } else {
        return null;
    }
}
 
Example #11
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public PeopleInterface getPeopleInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getPeopleInterface();
    } else {
        return null;
    }
}
 
Example #12
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public GroupsInterface getGroupsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getGroupsInterface();
    } else {
        return null;
    }
}
 
Example #13
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public UrlsInterface getUrlsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getUrlsInterface();
    } else {
        return null;
    }
}
 
Example #14
Source File: PhotoFragment.java    From android-opensource-library-56 with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mTask = new AsyncTask<Void, Void, PhotoList>() {
        protected PhotoList doInBackground(Void... params) {
            Log.d(TAG, "doInBackground");

            final Flickr f = new Flickr(API_KEY, API_SECRET);

            SearchParameters param = new SearchParameters();
            param.setText("coffee");

            try {
                return f.getPhotosInterface().search(param, 20, 1);
            } catch (Exception e) {
                e.printStackTrace();
            }

            return null;
        };

        protected void onPostExecute(PhotoList photolist) {
            if (photolist == null) {
                setEmptyText("load failed.");
            } else {
                ImageAdapter adapter = new ImageAdapter(getActivity(), photolist);
                setListAdapter(adapter);
            }
        };
    }.execute();
}
 
Example #15
Source File: Uploader.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct an Uploader.
 * 
 * @param apiKey
 *            The API key
 */
public Uploader(String apiKey, String sharedSecret) {
	try {
		this.apiKey = apiKey;
		this.sharedSecret = sharedSecret;
		this.transport = new REST(Flickr.DEFAULT_API_HOST);
		this.transport.setResponseClass(UploaderResponse.class);
	} catch (ParserConfigurationException e) {
		throw new RuntimeException(e.getMessage(), e);
	}
}
 
Example #16
Source File: OAuthInterface.java    From flickr-uploader with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Build the authentication URL using the given permission and frob.
 * 
 * The hostname used here is www.flickr.com. It differs from the api-default api.flickr.com.
 * 
 * @param permission
 *            The Permission
 * @param frob
 *            The frob returned from getFrob()
 * @return The URL
 * @throws MalformedURLException
 */
public URL buildAuthenticationUrl(Permission permission, OAuthToken oauthToken) throws MalformedURLException {
	List<Parameter> parameters = new ArrayList<Parameter>();
	parameters.add(new Parameter(PARAM_OAUTH_TOKEN, oauthToken.getOauthToken()));
	if (permission != null) {
		parameters.add(new Parameter("perms", permission.toString()));
	}

	int port = oauthTransport.getPort();
	String path = "/services/oauth/authorize";

	return UrlUtilities.buildUrl(Flickr.DEFAULT_API_HOST, port, path, parameters);
}
 
Example #17
Source File: FlickrApi.java    From GestureViews with Apache License 2.0 5 votes vote down vote up
@Background(singleThread = true)
@Subscribe(LOAD_IMAGES_EVENT)
private static synchronized EventResult loadImages(int count) throws Exception {
    SearchParameters params = new SearchParameters();
    params.setText(SEARCH_QUERY);
    params.setSafeSearch(Flickr.SAFETYLEVEL_SAFE);
    params.setSort(SearchParameters.RELEVANCE);
    params.setLicense(LICENCE_ID);
    params.setExtras(photoParams);

    boolean hasNext = hasNext();

    final PhotosInterface flickrPhotos = new Flickr(API_KEY).getPhotosInterface();
    while (photos.size() < count && hasNext) {
        final PhotoList loaded = flickrPhotos.search(params, PER_PAGE, pages.size() + 1);
        pages.add(loaded);
        photos.addAll(loaded);

        hasNext = hasNext();
    }

    int resultSize;
    if (photos.size() >= count) {
        resultSize = count;
    } else {
        resultSize = photos.size();
    }

    List<Photo> result = new ArrayList<>(photos.subList(0, resultSize));
    if (!hasNext) {
        hasNext = photos.size() > count;
    }

    return EventResult.create().result(result, hasNext).build();
}
 
Example #18
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public PoolsInterface getPoolsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getPoolsInterface();
    } else {
        return null;
    }
}
 
Example #19
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public FavoritesInterface getFavoritesInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getFavoritesInterface();
    } else {
        return null;
    }
}
 
Example #20
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public ContactsInterface getContactsInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getContactsInterface();
    } else {
        return null;
    }
}
 
Example #21
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public PhotosInterface getPhotosInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getPhotosInterface();
    } else {
        return null;
    }
}
 
Example #22
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public InterestingnessInterface getInterestingInterface() {
    Flickr f = getFlickr();
    if (f != null) {
        return f.getInterestingnessInterface();
    } else {
        return null;
    }
}
 
Example #23
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #24
Source File: FlickrHelper.java    From glimmr with Apache License 2.0 5 votes vote down vote up
public Flickr getFlickr() {
    try {
        return new Flickr(Keys.API_KEY, Keys.API_SECRET, new REST());
    } catch (ParserConfigurationException e) {
        return null;
    }
}
 
Example #25
Source File: StackWidgetService.java    From glimmr with Apache License 2.0 5 votes vote down vote up
private List<Photo> getContactsPhotos() throws Exception {
    OAuthToken token = mOAuth.getToken();
    Flickr f = FlickrHelper.getInstance().getFlickrAuthed(
            token.getOauthToken(), token.getOauthTokenSecret());
    boolean justFriends = false;
    boolean singlePhoto = false;
    boolean includeSelf = false;
    return f.getPhotosInterface().getContactsPhotos(
            Constants.FETCH_PER_PAGE, Constants.EXTRAS,
            justFriends, singlePhoto, includeSelf, PAGE,
            Constants.FETCH_PER_PAGE);
}
 
Example #26
Source File: StackWidgetService.java    From glimmr with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #27
Source File: StackWidgetService.java    From glimmr with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #28
Source File: PhotosetsInterface.java    From flickr-uploader with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Convenience method.
 * 
 * Calls getPhotos() with Extras.MIN_EXTRAS and Flickr.PRIVACY_LEVEL_NO_FILTER.
 * 
 * This method does not require authentication.
 * 
 * @see com.gmail.yuyang226.flickr.photos.Extras
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_NO_FILTER
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_PUBLIC
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FAMILY
 * @see com.gmail.yuyang226.flickr.Flickr#PRIVACY_LEVEL_FRIENDS
 * @param photosetId
 *            The photoset ID
 * @param perPage
 *            The number of photos per page
 * @param page
 *            The page offset
 * @return PhotoList The Collection of Photo objects
 * @throws IOException
 * @throws FlickrException
 * @throws JSONException
 */
public PhotoList getPhotos(String photosetId, int perPage, int page) throws IOException, FlickrException, JSONException {
	return getPhotos(photosetId, Extras.MIN_EXTRAS, Flickr.PRIVACY_LEVEL_NO_FILTER, perPage, page);
}