Get Facebook Pages using c#
Hi All,
I have a requirement while working on my project . that is share data on facebook fan page(that the login user admin of those pages).
I am using following code.
protected void Page_Load(object sender, EventArgs e)
{
if (Request["code"] == null)
{
Response.Redirect("https://graph.facebook.com/oauth/authorize?client_id=" + AppID + "&redirect_uri="+Request.Url.AbsoluteUri+"&scope=manage_pages,publish_stream");
}
else
{
Dictionary<string, string> tokens = new Dictionary<string, string>();
string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
AppID, Request.Url.AbsoluteUri, "manage_pages,publish_stream", Request["code"].ToString(), AppSecret);
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string vals = reader.ReadToEnd();
foreach (string token in vals.Split('&'))
{
tokens.Add(token.Substring(0, token.IndexOf("=")), token.Substring(token.IndexOf("=") + 1, token.Length - token.IndexOf("=") - 1));
}
}
string access_token = tokens["access_token"];
var fb = new FacebookClient(access_token) { AppId = AppID, AppSecret = AppSecret };
List<string> pagesIds = new List<string>();
dynamic results = fb.Get("/me/accounts");
foreach (var result in results.data)
{
pagesIds.Add(result.id);
}
}
}
But at this line "dynamic results = fb.Get("/me/accounts"); " I got empty json dataset like {data:[]} for users.
how do I resolve this?