Flickr4Java icon indicating copy to clipboard operation
Flickr4Java copied to clipboard

Add flickr.people.search

Open ctaity opened this issue 4 years ago • 7 comments

Subject of the issue

Please add to PeopleInterface the method flickr.people.search

Your environment

  • 2.16
  • 1.8

ctaity avatar Apr 03 '21 03:04 ctaity

Hi @ctaity I can't find that method in The Flickr API documentation. Do you have any more details about it please?

boncey avatar May 03 '21 15:05 boncey

Yes, is not document but....

private static final String SEARCH_METHOD = "flickr.people.search";

private URI getSearchUri(int page, String searchName) throws URISyntaxException, IOException {
		return new URIBuilder(API_URL)
				.addParameter("username", searchName)
				.addParameter("api_key", this.getSiteToken())
				.addParameter("method", SEARCH_METHOD)
				.addParameter("exact", "0")
				.addParameter("per_page", String.valueOf(RESULTS_PER_PAGE))
				.addParameter("perPage", String.valueOf(RESULTS_PER_PAGE))
				.addParameter("page", String.valueOf(page))
				.addParameter("loadFullContact", "1")
				.addParameter("format", "json")
				.addParameter("show_more", "1")
				.addParameter("nojsoncallback", "1")
				.addParameter("extras", "date_joined,path_alias,rev_ignored,rev_contacts,icon_urls,location,rev_contact_count,use_vespa")
				.build();
	}

and now i am geeting the site token from flickr index.

private static final String REGEX_SITE_KEY = "root.YUI_config.flickr.api.site_key = \"(?<key>.*)\"";

protected void refreshSiteKey() throws IOException {
		final String source = RequestUtils.getDocument(FLICKR_URL).html();
		final Matcher siteKeyMatcher = PATTERN_SITE_KEY.matcher(source);
		final Matcher siteKeyExpiresMatcher = PATTERN_SITE_KEY_EXPIRES.matcher(source);

		if (!siteKeyMatcher.find() || !siteKeyExpiresMatcher.find())
			throw new IOException("Cannot get site_key or expires");

		siteKey = siteKeyMatcher.group("key");
		expiresSiteKey = 1000 * Long.valueOf(siteKeyExpiresMatcher.group("ts")); //with miliseconds
	}

	protected String getSiteToken() throws IOException {
		if (expiresSiteKey < System.currentTimeMillis() + SAFE_SEARCH_TIME)
			this.refreshSiteKey();
		return siteKey;
	}

ctaity avatar May 03 '21 22:05 ctaity

Hello. I can't get it working sorry. I did some test code to call the method but it just failed.

How does this differ from flickr.people.findByUsername anyway? Can't you just use that?

boncey avatar May 04 '21 16:05 boncey

can you share with me the test? This search is called from flickr in the public search of profiles, is a different search, is not only by username.

ctaity avatar May 04 '21 17:05 ctaity

private static final String API_URL = "https://api.flickr.com/services/rest";

ctaity avatar May 04 '21 22:05 ctaity

Here you go, I've pushed my branch. https://github.com/boncey/Flickr4Java/tree/user-search

Refer to the README on how to run the tests.

boncey avatar May 06 '21 16:05 boncey

Thanks, i going to checkout.

ctaity avatar May 06 '21 22:05 ctaity