Unlimited IP Pool
Cost Effective IP Pool
Unlimited IP Pool
Cost Effective IP Pool
Data Sourcing for LLMs & ML
Accelerate ventures securely
Proxy selection for complex cases
Some other kind of copy
Protect your brand on the web
Reduce ad fraud risks
Social media movements are organized initiatives that use internet platforms like Facebook, Instagram, TikTok, or Twitter to gain leverage and raise awareness of social, political, environmental, and cultural concerns. The real time nature of social media combined with its vast audience and the right strategy can make it fairly easy to go viral.
The impact of the social media movement in our society has raised a lot of concern regarding whether or not the government should exercise more control when it comes to the use of social media. The adoption of technologies for social media data tracking and analysis allows organizations to gain valuable insights into user movements and behavior on social media. This blog will guide you through building a Facebook profile location tracker using The Social Proxy Scraper API and AI tools.
A Facebook profile location tracker is a tool that collects location data pertaining to posts, check-ins, and features like the share feature through Messenger. The data collected get analyzed to improve and influence user activity. They can also produce a visual representation of where users have been based on their shared content.
Facebook location trackers are important because their data provides a visual representation of user location and allows social media mapping, increasing organizational access to marketing information. This helps brands understand market trends, customer behavior, create local campaigns, and track influencer activity.
The Social Proxy offers reliable tools that are easy to use and can help you tap into rich data. Some of these tools include data tools (e.g. AI Social Lookup, AI Geo Lookup, and AI Street View), mobile proxies, residential proxies, and The Scraper API, each providing a different set of data.
The Scraper API provides more comprehensive data from social media platforms that can be narrowed down to a specific data type. Meanwhile, residential proxies provide you with information about geolocated residential IPs, which requires you indicate the country, state, and city.
The Geolocation API is a service that accepts an HTTPS request with the cell tower and WiFi access points that a mobile client can detect. Visit this link to create an account and gain access to The Social Proxy Dashboard.
You’ll need the following in order to build a Facebook profile location tracker:
Install Node.js on Windows/Mac via Installer:
Set up a virtual environment
We’ll use Node Version Manager (NVM) to manage different versions of Node.js for different projects, while npm and npx for managing dependencies. Running NVM on Windows requires a specific version called nvm-windows, as the original NVM was developed primarily for Unix-based systems (Linux/macOS). Here’s how to install and use nvm-windows:
Once you’ve successfully installed your Node.js and set up your virtual environment on Windows, you’ll need to create an account and generate a Scraper API with The Social Proxy.
Let’s use the Scraper API Key and Secret that we’ve generated following the instruction above to scrape text and images from a specific Facebook profile with other libraries like Axios, and Cheerio. First we need to create a directory. Open your terminal and run the code below on Git Bash or PowerShell:
Hp@dule-lab MINGW64 /c/ProjectsXYZ
$ mkdir facebook_profile_location_tracker
Next, cd into the folder you just created by running the following command:
Hp@dule-lab MINGW64 /c/ProjectsXYZ
$ cd facebook_profile_location_tracker
Install the libraries mentioned above:
Hp@dule-lab MINGW64 /c/ProjectsXYZ/facebook_profile_location_tracker
$ npm install cheerio
npm install openai axios request
Visit The Social Proxy Dashboard to get your API endpoint for Facebook. Here is our endpoint : GET /wp-json/tsp/facebook/v1/posts/node
Here is the script we’ll use to perform the scraping task:
const axios = require('axios');
const cheerio = require('cheerio');
//Facebook profile URL
const profileUrl = 'https://www.facebook.com/username';
//ScraperAPI URL
const socialProxyApiUrl = `https://thesocialproxy.com/wp-json/tsp/facebook/v1/posts/node?consumer_key=ck_5d08e0a7c419af9d7a90c76d1019559b53d9815a&consumer_secret=cs_9636ac43e09a78a4e8ab06181d061836ded1af39&node_id=UzpfSTQ6MTAxMTUxODY0ODg0ODIxNDE=&url=${encodeURIComponent(profileUrl)}`
// Scrape the Facebook profile
async function scrapeFacebookProfile() {
try {
// Make a request to the Social Proxy Scraper API
const { data } = await axios.get(socialProxyApiUrl, {headers:{"Content-Type": "application/json"}});
//Load the HTML using cheerio
const $ = cheerio.load(data);
//Extract the profile name
const profileName = $('title').text();
console.log('Profile Name', profileName);
//Extract text posts
const posts = $('div._5pbx').map((i, element) => $(element).text()).get();
console.log('Posts:', posts);
//Extract images from the profile
const images = $('img').map((i, element) => $(element).attr('src')).get();
console.log('Images:', images);
} catch (error){
console.log('Error scraping profile:', error.message);
}
}
scrapeFacebookProfile();
Running the above script using a Facebook profile URL will allow the script to scrape for text and images displaying them in an array.
To store data that has been scrapped by our previous script, we’ll write a function to fetch all locations from the scraped data.
// Function to retrieve location data
async function fetchLocations(){
try{
const response = await axios.get(`${socialProxyApiUrl}/location`);
console.log('Locations fetched:', response.data);
return response.data; // This would return an array of locations
} catch (error) {
console.error('Error fetching locations:', error);
}
}
fetchLocations();
With the fetchLocations function defined and executed, we’ll get the result shown below:
Now that we’ve succeeded in fetching all locations, we can store the data.
async function storeLocation(locationData) {
try {
const response = await axios.post(`${socialProxyApiUrl}`, locationData);
console.log('Location stored:', response.data);
} catch (error) {
console.error('Error storing location:', error)
}
}
Visit OpenAI and reference the following steps to use ChatGPT API to identify location names in text.
Install the SDK package for OpenAI using npm
Hp@dule-lab MINGW64 /c/ProjectsXYZ/facebook_profile_location_tracker
$ npm install openai
Use “import openai” in your code and write a script to identify locations in text.
// Function to extract locations
async function extractLocations(text) {
const prompt = `Identify all location names (countries, cities, landmarks) in the following text: ${text}`;
try {
const response = await openai.createChatCompletion({
model: "gpt-4", // or 'gpt-3.5-turbo'
messages: [
{ role: "system", content: "You are a helpful assistant that extracts location names." },
{ role: "user", content: prompt },
],
});
// Extract the result from the response
return response.data.choices[0].message.content;
} catch (error) {
console.error("Error extracting locations:", error);
}
}
// Example text caption
const text = "This in-person event will be held at NTA Road, Port Harcourt, Nigeria.";
extractLocations(text).then(locations => {
console.log(locations);
});
You’ll receive the following output:
Text: “This in-person event will be held at NTA Road, Port Harcourt, Nigeria.”
An example of what the API returns: “NTA Road, Port Harcourt, Nigeria”
We’ll use The Social Proxy GEOLOCATE-IMAGE endpoint to upload an image and AI Geo Lookup to identify the location.
API endpoint: POST /wp-json/tsp/geolocate/v1/image
// Uploading image using the Geolocate-image endpoint
async function detectLandmarks(imagePath) {
// Performs landmark detection on the image file
const [result] = await client.landmarkDetection(imagePath);
const landmarks = result.landmarkAnnotations;
if (landmarks.length === 0) {
return "No landmarks found.";
}
const locations = landmarks.map(landmark => ({
description: landmark.description,
score: landmark.score, // Confidence score
locations: landmark.locations.map(location => ({
latitude: location.latLng.latitude,
longitude: location.latLng.longitude
}))
}));
return locations;
}
// Example usage
(async () => {
const imageUpload = 'C:\ProjectsXYZ\facebook_profile_location_tracker\image\Dule-Martins.jpg'; //Upload image from local devices
const imagePath = `https://thesocialproxy.com/wp-json/tsp/geolocate/v1/image?consumer_key={CONSUMER_KEY}&consumer_secret={CONSUMER_SECRET}=&url=${encodeURIComponent(imageUpload)}`; // Replace with the path to your image
const landmarks = await detectLandmarks(imagePath);
console.log(landmarks);
})();
While on your dashboard, navigate from your sidebar to the “Data Tools” and click on “AI Geo Lookup” to upload the file you want AI to analyze and find the location associated with it.
In this section, we’ll use Leaflet, a JavaScript library to map our data. The data used includes timestamps and coordinates.
Here is our HTML, CSS file with Leaflet.js:
Locational movement on a map
Shown above is the head tag of an HTML file with a CSS tag, links to Leaflet CSS, and its Javascript source link including a TimeDeminsion plugin. Below we can see the body tag.
You can see the end result of our map below.
To build a Facebook profile location tracker, you need The Social Proxy consumer_key and consumer_secret. Using these key values authenticates the process of data access for mapping the movement of a user over time, while the Geo AI Lookup gives the latitude and longitude of the image uploaded.