Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Andreas, I've also been looking for an "email-to-id" ellegant solution and couldn't find one. However, as you said, screen scraping is not such a bad idea in this case, because emails are unique and you either get a single match or none. As long as Facebook don't change their search page drastically, the following will do the trick:</p> <pre class="lang-java prettyprint-override"><code>final static String USER_SEARCH_QUERY = "http://www.facebook.com/search.php?init=s:email&amp;q=%s&amp;type=users"; final static String USER_URL_PREFIX = "http://www.facebook.com/profile.php?id="; public static String emailToID(String email) { try { String html = getHTML(String.format(USER_SEARCH_QUERY, email)); if (html != null) { int i = html.indexOf(USER_URL_PREFIX) + USER_URL_PREFIX.length(); if (i &gt; 0) { StringBuilder sb = new StringBuilder(); char c; while (Character.isDigit(c = html.charAt(i++))) sb.append(c); if (sb.length() &gt; 0) return sb.toString(); } } } catch (Exception e) { e.printStackTrace(); } return null; } private static String getHTML(String htmlUrl) throws MalformedURLException, IOException { StringBuilder response = new StringBuilder(); URL url = new URL(htmlUrl); HttpURLConnection httpConn = (HttpURLConnection) url.openConnection(); httpConn.setRequestMethod("GET"); if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) { BufferedReader input = new BufferedReader(new InputStreamReader(httpConn.getInputStream()), 8192); String strLine = null; while ((strLine = input.readLine()) != null) response.append(strLine); input.close(); } return (response.length() == 0) ? null : response.toString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload