问题描述
如果我有用户名,我想要检索一个Facebook用户ID。
这是从图API中弃用的,但是如果我有用户名,我想知道如何获取id。
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.
推荐答案
我做了R& D,发现给定的网站没有使用API从用户名中获取用户名。
他们正在使用另一种无效的机制。
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.
我已经找到了一种从用户名中找到userid的机制。
I have found 1 mechanism to find the userid from the username.
下面是标识如何从用户名中找到userid的c#代码。
我试图从Facebook的URL读取HTML。并尝试阅读下面的元标记来识别userid。
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代码
<meta property="al:android:url" content="fb://profile/USERID">
功能
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 "";
}
要求
- 我使用HtmlAgilityPack.dll加载html并解析它像XML。
- 要测试调用下面的函数。
findUserIdfromUsername(); - 我只测试3-4个网址并获得正确的用户标识。
- 我没有使用任何API来查找USERID。
- 我的英文和步骤不是很好。所以请管理。
- 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.
这篇关于从用户名检索Facebook用户标识的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!