I want to retrieve the UID or list of people who liked a Facebook post using Javascript. I've found some questions about that but most of them are outdated. For instance, some of them recommended using FQL but it's already deprecated and another to use Graph API. But to retrieve that information from pages I'm not the owner of, I need the "Page Public Content Access" authorization from Facebook. Unfortunately, it's taking too much time, and not sure they will give it to me.
So, is it possible to get that information without the API? I already made some tries but was not really successful.
Does someone have an idea of how I can do that? Thanks.
Here are my extension files.
manifest.json
{
"manifest_version": 3,
"name": "PageReact",
"version": "1.0.0",
"action": {
"default_icon": "icon.png",
"default_title": "PageReact",
"default_popup": "index.html"
},
"icons": {
"128": "icon.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["content.js"]
}
],
"background": {
"service_worker": "background.js"
},
"host_permissions": ["http://*/", "https://*/"],
"permissions": ["tabs", "notifications", "activeTab", "scripting", "storage"]
}
content.js
var initLog = "Activating 'PageReact'";
console.log(initLog);
for (var i=0; i < document.getElementsByClassName("gewbibgg").length; i++) {
if (document.getElementsByClassName("gewbibgg")[i].src == "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' viewBox='0 0 16 16'%3e%3cdefs%3e%3clinearGradient id='a' x1='50%25' x2='50%25' y1='0%25' y2='100%25'%3e%3cstop offset='0%25' stop-color='%2318AFFF'/%3e%3cstop offset='100%25' stop-color='%230062DF'/%3e%3c/linearGradient%3e%3cfilter id='c' width='118.8%25' height='118.8%25' x='-9.4%25' y='-9.4%25' filterUnits='objectBoundingBox'%3e%3cfeGaussianBlur in='SourceAlpha' result='shadowBlurInner1' stdDeviation='1'/%3e%3cfeOffset dy='-1' in='shadowBlurInner1' result='shadowOffsetInner1'/%3e%3cfeComposite in='shadowOffsetInner1' in2='SourceAlpha' k2='-1' k3='1' operator='arithmetic' result='shadowInnerInner1'/%3e%3cfeColorMatrix in='shadowInnerInner1' values='0 0 0 0 0 0 0 0 0 0.299356041 0 0 0 0 0.681187726 0 0 0 0.3495684 0'/%3e%3c/filter%3e%3cpath id='b' d='M8 0a8 8 0 00-8 8 8 8 0 1016 0 8 8 0 00-8-8z'/%3e%3c/defs%3e%3cg fill='none'%3e%3cuse fill='url(%23a)' xlink:href='%23b'/%3e%3cuse fill='black' filter='url(%23c)' xlink:href='%23b'/%3e%3cpath fill='white' d='M12.162 7.338c.176.123.338.245.338.674 0 .43-.229.604-.474.725a.73.73 0 01.089.546c-.077.344-.392.611-.672.69.121.194.159.385.015.62-.185.295-.346.407-1.058.407H7.5c-.988 0-1.5-.546-1.5-1V7.665c0-1.23 1.467-2.275 1.467-3.13L7.361 3.47c-.005-.065.008-.224.058-.27.08-.079.301-.2.635-.2.218 0 .363.041.534.123.581.277.732.978.732 1.542 0 .271-.414 1.083-.47 1.364 0 0 .867-.192 1.879-.199 1.061-.006 1.749.19 1.749.842 0 .261-.219.523-.316.666zM3.6 7h.8a.6.6 0 01.6.6v3.8a.6.6 0 01-.6.6h-.8a.6.6 0 01-.6-.6V7.6a.6.6 0 01.6-.6z'/%3e%3c/g%3e%3c/svg%3e") {
var like_button = document.getElementsByClassName("gewbibgg")[i]
}
}
like_button.click();
setTimeout(function get_profile_href() {
var profiles_list =
document.body.children[0].children[1].children[0].children[0].children[6]
.children[0].children[0].children[0].children[0].children[1].children[0]
.children[0].children[0].children[0].children[0].children[0].children[1]
.children[1].children[0].children[0].children[0];
var profiles_href = [];
for (var i = 0; i < profiles_list.children.length; i++) {
profiles_href.push(
profiles_list.children[
i
].children[0].children[0].children[0].children[0].children[0].getAttribute(
"href"
)
);
}
popup_close_button =
document.body.children[0].children[1].children[0].children[0].children[6]
.children[0].children[0].children[0].children[0].children[1].children[0]
.children[0].children[0].children[0].children[0].children[0].children[0]
.children[0].children[1].children[0];
popup_close_button.click();
console.log(profiles_href);
chrome.runtime.sendMessage({message: "profile_href_loaded", profiles_href: profiles_href}, function(response) {
console.log('sent');
});
}, 5000);
background.js
chrome.runtime.onMessage.addListener((response, callback) => {
if (response.message === "profile_href_loaded") {
profiles_href = response.profiles_href
console.log(profiles_href)
chrome.storage.sync.set({ profiles_href });
}
console.log('received')
});
popup.js
const sendMessageId = document.getElementById("sendmessageid");
localStorage.removeItem("profiles_href")
console.log(localStorage.getItem("profiles_href"))
sendMessageId.addEventListener("click", async () => {
let [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["content.js"],
}, function () {
chrome.storage.sync.get("profiles_href", ({ profiles_href }) => {
console.log(profiles_href)
for (var i = 0; i < profiles_href.length; i++) {
var no = document.createElement("td");
var no_text = document.createTextNode(i);
no.appendChild(no_text);
var uid = document.createElement("td");
var uid_text = document.createTextNode(profiles_href[i]);
uid.appendChild(uid_text);
var tr = document.createElement("tr");
tr.appendChild(no);
tr.appendChild(uid);
var element = document.getElementById("list_of_uid");
element.appendChild(tr);
}
});
});
});
index.html
<!DOCTYPE html>
<html>
<head>
<title>PageReact</title>
<meta charset="utf-8">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<style>
body {
width: 500px;
}
button {
background-color: #336dab;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
font-size: 16px;
}
</style>
</head>
<body>
<div class="container mt-3" style="width: 450px;">
<h2 class="text-center">UID's of people who had reacted</h2>
<button id="sendmessageid">Get UID</button>
<table class="table table-bordered">
<thead>
<tr>
<th>N°</th>
<th>UID</th>
</tr>
</thead>
<tbody id = "list_of_uid">
</tbody>
</table>
</div>
</body>
<script type="module" src="popup.js"></script>
</html>