使用C#从facebook获取FB页面数据 [英] Getting FB Page data from facebook using C#
问题描述
在我的桌面应用程序中,我想阅读特定 Facebook 页面的墙上帖子、消息、喜欢计数等(不适用于 Facebook 用户)
In my Desktop application, I want to read the Wall posts,Messages, Like counts etc for a particular Facebook page (not for a facebook user)
我浏览了这篇文章获取用户数据(在 stackoverflow 上).我想实现同样的事情,但对于 FB 页面.
I went through this post get user data(on stackoverflow). I want to achieve the same thing but for a FB page.
我已准备好创建一个 Facebook 应用程序来实现此目的,并让用户授予提取数据的权限.
I am ready to create a facebook application to achieve this and have the user to give permission to pull the data.
请就上述问题提出建议.
Please advice on the above.
推荐答案
您需要一个访问令牌才能从 Facebook 获取页面数据.首先使用以下 URL 和您的 facebook 应用程序参数获取访问令牌:
You need an access token to get page data from Facebook. First get an access token using below URL with your facebook application's parameters:
https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={yourappid}&client_secret={yourappscret}
然后您可以使用返回令牌调用 Facebook Graph API
Then you can call the Facebook Graph API with returning token
一般:https://graph.facebook.com/wikipedia?access_token={token}
帖子:https://graph.facebook.com/wikipedia/posts?access_token={token}
示例代码是;
class Program
{
static void Main(string[] args)
{
var client = new WebClient();
string oauthUrl = string.Format("https://graph.facebook.com/oauth/access_token?type=client_cred&client_id={0}&client_secret={1}", "appid", "appsecret");
string accessToken = client.DownloadString(oauthUrl).Split('=')[1];
string pageInfo = client.DownloadString(string.Format("https://graph.facebook.com/wikipedia?access_token={0} ", accessToken));
string pagePosts = client.DownloadString(string.Format("https://graph.facebook.com/wikipedia/posts?access_token={0} ", accessToken));
}
}
这篇关于使用C#从facebook获取FB页面数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!