B4J Question Any Facebook API code?

drgottjr

Expert
Licensed User
Longtime User
you can page scrape some data (eg, likes) with httputils2 and a little regex. i had no trouble with a few celebrities. BUT a typical facebook page consists of a relatively small base page (37K bytes), and the meat is made up of numerous .js files. those files are not captured by downloading the main .html page. you would have to know what those .js files were and download them individually. you would also have to know what each of those pages did. i looked. frankly, not worth the time.

another possibility for is to download the entire page (including ancillary .js files) in a webview. you could then capture the entire content. (https://www.b4x.com/android/forum/threads/how-to-get-the-html-code-of-a-webview-object.47207/). once that was in hand, you could peruse it at your leisure to look for where the data you're looking for appear (eg, in certain <div>'s). once you knew that you could find those <div>'s, you can use regex to find them for any page you downloaded.

data such as "likes", "follows", etc, are loaded dynamically by facebook into the base html template. many of these data cannot be seen by simply looking at the source in a browser. they are added later in identifiable elements. those elements, if known, can be found and data within them captured. as indicated above, once i found which element contained, eg the "likes" value, i had no difficulty looking for that element in other pages and capturing the "likes" value for those pages. i don't know exactly which data, you're looking for, but it will involve a fair amount of study. the actual capture is trivial, if you know which elements hold the values you're looking for.

as an example:
' <div class="_4bl9"><div>36,141,983 people like this</div>
' <div class="_4bl9"><div>57,629,651 people follow this</div>

div of class "_4bl9" hold a nugget (if this is what you're into).
 
Upvote 0

ElliotHC

Active Member
Licensed User
It's a public page so most likely the same as a celebrity. Are you able to share your code?
If I download the page, I don't see any of that data as you say.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
there's no actual code since i don't know what you're looking for. i picked "likes" and saw "people like this" buried in a div. it was buried in the same div for every page that i looked at. once you know where they put it, you use a regular expression to find that element. as i mentioned, the element i saw was
<div class="_4bl9"> it was immediately followed by a number and " people like this"). they don't want you using their data and because they use templates and stuff fields dynamically, it's going to be difficult. you don't know exactly when the fields are stuffed. if you were a tech company, you would have a couple hundred kids pouring over every inch of facebook code in exchange for some cigarettes. it's you vs zuckerberg.

i'm sure there's a developer's api for facebook. if it's in java, you might be able to get it to work in b4x. it may expose data for inclusion in facebook-related apps.
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
here, at the top of m.facebook.com/beyonce there's:
<meta name="description" content="Beyoncé. 60,575,047 likes

captured it from webview content.

also
<meta name="description" content="The Royal Family. 5,111,469 likes
<div class="_4bl9"><div>5,111,474 people like this</div></div><
 
Last edited:
Upvote 0
Top