使用C#从Facebook获取FB页面数据 [英] Getting FB Page data from facebook using C#

查看:83
本文介绍了使用C#从Facebook获取FB页面数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的桌面应用程序中,我想阅读一个特定的 Facebook页面 (不是用于Facebook用户)的Wall帖子,消息等等。



我经历了这篇文章获取用户数据(在stackoverflow上)。我想要实现同样的事情,但是对于FB页面。



我准备好创建一个Facebook应用程序来实现这一点,并让用户授予拉取数据的权限



请咨询上述。

解决方案

访问令牌以从Facebook获取页面数据。
首先使用您的Facebook应用程序的参数,使用以下URL获取访问令牌:



https://graph.facebook.com/oauth / access_token?type = client_cred& client_id = {yourappid}& client_secret = {yourappscret}



然后你可以调用Facebook Graph API返回令牌



一般: https://graph.facebook.com/wikipedia?access_token= {token} / p>

帖子: 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));
}
}


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)

I went through this post get user data(on stackoverflow). I want to achieve the same thing but for a FB page.

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.

解决方案

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}

Then you can call the Facebook Graph API with returning token

General: https://graph.facebook.com/wikipedia?access_token={token}

Posts: https://graph.facebook.com/wikipedia/posts?access_token={token}

An example code would be;

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆