Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flickr.people.search #443

Open
ctaity opened this issue Apr 3, 2021 · 7 comments
Open

Add flickr.people.search #443

ctaity opened this issue Apr 3, 2021 · 7 comments
Assignees

Comments

@ctaity
Copy link

ctaity commented Apr 3, 2021

Subject of the issue

Please add to PeopleInterface the method flickr.people.search

Your environment

  • 2.16
  • 1.8
@boncey boncey self-assigned this Apr 7, 2021
@boncey
Copy link
Owner

boncey commented May 3, 2021

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

@ctaity
Copy link
Author

ctaity commented May 3, 2021

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;
	}

@boncey
Copy link
Owner

boncey commented May 4, 2021

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?

@ctaity
Copy link
Author

ctaity commented May 4, 2021

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
Copy link
Author

ctaity commented May 4, 2021

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

boncey pushed a commit that referenced this issue May 6, 2021
Example code for issue #443
@boncey
Copy link
Owner

boncey commented May 6, 2021

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.

@ctaity
Copy link
Author

ctaity commented May 6, 2021

Thanks, i going to checkout.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants