I want to retrieve a Facebook user id if I have his username.
This was deprecated from the graph API but I would like to know a work around on getting the id if i have the username.
There is a website that does that but I am not sure how they do it.
I did the R&D and found that the given website is not using the API to fetch userid from the username.
They are using another mechanism which is not valid.
I have found 1 mechanism to find the userid from the username.
Below is the c# code which identify how to find userid from username.
I tried to read the HTML from facebook url. and trying to read below meta tag to identify userid.
META Code
<meta property="al:android:url" content="fb://profile/USERID">
Function
public string findUserIdfromUsername(string facebookURL)
{
try
{
HtmlWeb web = new HtmlWeb();
HtmlDocument doc = web.Load(facebookURL);
List<String> keyLst = doc.DocumentNode
.SelectSingleNode("//meta[@property='al:android:url']")
.Attributes["content"].Value
.Split(',').ToList();
foreach (string strkey in keyLst)
{
string[] arrTemp = strkey.Split('/');
int arrlength = arrTemp.Count();
string facebookUserID = arrlength > 0 ? (arrTemp[arrlength - 1]) : strkey;
facebookUserID = facebookUserID.Replace("?id=", "");
return facebookUserID;
}
}
catch (Exception ex)
{
}
return "";
}
Requirement
- I have used "HtmlAgilityPack.dll" to load the html and parse it like XML.
- To test call the function like below.
findUserIdfromUsername("https://facebook.com/USERNAME");
- I have only test 3-4 urls and getting right userid.
- I am not using any API to find USERID.
- My English and steps are not too much good. So please manage it.