Может кто-нибудь, пожалуйста, дайте мне знать, как я могу получить сообщения, опубликованные владельцем аккаунта на стене.В моем случае мне нужно получить посты со страницы нашей компании в Facebook.
Я пытался использовать Graph API для получения результатов, но у меня проблемы с получением токена доступа.
Чтобы получить Access Token, я использовал следующий код:
public string GetAccessToken()
{
string params = string.Format("grant_type=client_credentials&client_id={0}&client_secret={1}", this.ApplicationId, this.ApplicationSecret);
FacebookResponse response = this.IssueRequest(RequestAction.POST, "https://graph.facebook.com/oauth/access_token", params);
if ((response.HttpResponseCode == HttpStatusCode.OK) && (response.JSON != string.Empty))
{
this.AccessToken = response.JSON.Split(new char[] { '=' })[1];
}
return this.AccessToken;
}
Чтобы получить UserData, я использовал ниже:
public string GetUserData(string UserId, UserConnection UC)
{
string uRL = string.Empty;
if (this.AccessToken != string.Empty)
{
uRL = string.Format("https://graph.facebook.com/{0}/{1}?access_token={2}", UserId, Common.GetStringValue(UC), this.AccessToken);
}
else
{
uRL = string.Format("https://graph.facebook.com/{0}/{1}", UserId, Common.GetStringValue(UC));
}
FacebookResponse response = this.IssueRequest(RequestAction.POST, uRL, string.Empty);
if ((response.HttpResponseCode == HttpStatusCode.OK) && (response.JSON != string.Empty))
{
return response.JSON;
}
return null;
}
В своем коде я вызываю Graph API, как показано ниже:
FacebookGraphApi fg = new FacebookGraphApi();
FacebookGraphApi.FacebookUserFeed[] Feed =
FacebookGraphApi.ParseUserFeed(fg.GetUserData(ApplicationId, FacebookGraphApi.UserConnection.FEED));
//Bind results to Repeater
rptFacebookFeed.DataSource = Feed;
rptFacebookFeed.DataBind();
The ParseUserFeed returns FacebookUserFeed[] array.
Спасибо, Рави