GET-PLACES-TIKTOK-FACEBOOK
Get TikTok and Facebook content of a specific place.
Output Screenshots
TikTok




Facebook




Implementation on Your Website
form.php
form.phpA form where user can input the platform of choice ("tiktok" or "facebook"), mainPlace (e.g. "Ipoh"), and name (e.g. "10 Studio Cafe")
get-places-tiktok-facebook.php
get-places-tiktok-facebook.phpImport
Importing Google Fonts and CSS
HTML Layout
The main layout which consists of the banner (TikTok/Facebook), and the content section which displays the TikTok/Facebook content for a specific place.
JavaScript for building the layout
Responsible for building the layout after the content is retrieved.
PHP cording for streams to TikTok or Facebook content
Retrieve Platform Value from POST Data:
Obtain the "platform" value from the POST data using
$_POST["platform"].
Display Banner Based on Platform:
Use an if-else statement to determine the platform.
If the platform is "tiktok," display a JavaScript banner using
showBanner('tiktok').If the platform is not "tiktok," display a JavaScript banner with the actual platform value.
Flush Output Buffer:
Flush the output buffer to ensure immediate display of content in the browser.
Retrieve Additional POST Data:
Get additional POST data such as "mainPlace" and "name" using
$_POST["mainPlace"]and$_POST["name"].
URL Encode Name and Main Place:
Encode the "name" and "mainPlace" variables using
urlencode().
Retrieve Platform Value Again:
Reassign the "platform" variable with the value from the POST data.
Process Based on Platform:
If the platform is "tiktok":
Construct a search text for TikTok by concatenating encoded name, encoded main place, and "tiktok."
Create a Google search URL using the constructed search text.
Fetch content from the Google search page using
file_get_contents().Parse the HTML content using a
DOMDocumentandXPath.Extract TikTok discover URLs from anchor tags and store them in an array.
If the array is empty, display a JavaScript function call for no TikTok results.
Otherwise, call the
forTikTokfunction with the first URL from the array.
If the platform is "facebook":
Construct a search text for Facebook by concatenating encoded name, encoded main place, and "facebook."
Call the
forFacebookfunction with the constructed search text.
PHP for TikTok content
Fetch TikTok Page Content
Use
file_get_contents($url)to retrieve the content of the TikTok page specified by the given URL.
Initialize Arrays for Data Storage
Create arrays to store various data extracted from the TikTok page, including video views, usernames, likes, titles, tags, tag views, image URLs, and links.
Initialize Error Flag
Set a flag,
$somethingWong, to false initially. This flag will be used to check if something went wrong during the extraction process.
Filter Author Links
Load the HTML content into a
DOMDocument.Use
XPathto find specific<div>elements with the classtiktok-1as5cen-DivWrapper e1cg0wnj1.Extract author anchors (
<a>tags) and construct complete URLs by appending them to "https://www.tiktok.com".Store the author links in the
linksArray.
Filter Video Views
Use
XPathto find<strong>elements within a<div>with the classtiktok-k7smtc-DivCoverFooter e1aajktk7.Extract the text content of the
<strong>elements, representing the number of likes, and store them in thevideoViewsArray.
Filter Usernames
Use
XPathto find<p>elements with the classtiktok-18g0m3y-PInfo-StyledH3UniqueId e1aajktk12.Extract the text content of the
<p>elements, representing usernames, and store them in theusernameArray.
Filter Likes
Use
XPathto find<span>elements with the classtiktok-1cgeagm-SpanLikes e1aajktk13.Extract the text content of the
<span>elements, representing the number of likes, and store them in thelikesArray.
Filter Title
Use
XPathto find<div>elements with the classtiktok-156kx37-DivVideoDescription e1aajktk10.Extract the text content from the 'title' attribute of the
<div>elements and store them in thetitleArray.
Filter Tags and Views
Use
XPathto find<div>elements with the classtiktok-1s2ovfk-DivContent eabhyw07that contain the word 'views'.Extract tag names, views, and construct tag links based on the content of these
<div>elements.Store tag names, views, and tag links in
tagArray,tagViewsArray, andtagLinksArray, respectively.Set
$somethingWongto true if no matching<div>elements are found.
Filter Images
Use
XPathto find<div>elements with the classtiktok-1jxhpnd-DivContainer e1yey0rl0.Extract image tags (
<img>elements) and get the source link (URL) of each image.Store the image URLs in the
imageURLArray.
Check for Errors
If
$somethingWongis true (indicating an issue during tag and view extraction), echo a JavaScript script to call thenoResult()function.
Display Results
If extraction is successful, echo JavaScript scripts to convert PHP arrays to JavaScript variables.
Call the
generateSectionHeaders()function to display the results using JavaScript.
PHP for Facebook content
Initialize Google Search URL:
Construct a Google search URL for images related to the provided keyword on Facebook.
Fetch Google Search Results:
Use
file_get_contentsto fetch the content of the Google search results page using the constructed URL.
Create DOMDocument:
Create a new
DOMDocumentto parse the HTML content of the Google search results.
Load HTML into DOMDocument:
Load the HTML content into the
DOMDocumentand set upXPathfor querying.
XPath Query for Href Attributes:
Use
XPathto query forhrefattributes of<a>elements within tables with a specific class (GpQGbf).
Process Facebook URLs:
Loop through the found
<a>elements and extract relevant Facebook URLs.
Check for Facebook URLs:
Check if the decoded URL contains 'facebook.com'.
Filter Facebook URLs:
Differentiate between Facebook post URLs and Facebook photo URLs.
Process Facebook Post URLs:
For post URLs, remove unwanted parts and check for characters after "/posts/".
Process Facebook Photo URLs:
For photo URLs, apply specific conditions to filter out unwanted URLs.
Check for Series of Numbers in Photo URLs:
Use a regular expression to check if there is a series of numbers before "/photos/" in the given URL.
Display Results or No-Result Message:
Check if any processed URLs are found, and either display the processed URLs or show a no-result message.
Remove Repeating Links:
Remove repeating links from the array of processed URLs to ensure uniqueness.
Display Processed URLs:
Echo JavaScript code to set a variable with JSON-encoded data containing the processed URLs.
Trigger JavaScript Function:
Echo JavaScript code to trigger the
addLocationBlocksfunction, which likely handles the display of the processed URLs.
Last updated