我正在尝试使用基于ASP.net MVC的Orchard CMS实现自定义模块,它将获取http请求并获得响应作为json数据并且我正在解析它,之后我的解析列表我想表示它我的观点我有一些问题,而我正在调用我的控制器动作,从我的视图中获取解析后的列表json数据我认为我现在做错了可以有人帮助我
这是我的代码块:
型号:
public class NewsDisplayRecord : ContentPartRecord
{
public NewsDisplayRecord()
{
//Facebook Fields
AppID = "*****";
AppSecret = "*****";
PageID = "****";
_consumerKey = "****";
_consumerSecret = "****";
access_token = "***-***";
access_token_secret = "****";
}
//Facebook fields
public virtual string AppID { get; set; }
public virtual string AppSecret { get; set; }
public virtual string PageID { get; set; }
//Twitter Fields
public virtual string _consumerKey { get; set; }
public virtual string _consumerSecret { get; set; }
public virtual string access_token { get; set; }
public virtual string access_token_secret { get; set; }
//General Fields
}
public class NewsDisplayPart : ContentPart<NewsDisplayRecord>
{
public string AppID
{
get { return Retrieve(r => r.AppID); }
set { Store(r => r.AppID, value); }
}
public string AppSecret
{
get { return Retrieve(r => r.AppSecret); }
set { Store(r => r.AppSecret, value); }
}
public string PageID
{
get { return Retrieve(r => r.PageID); }
set { Store(r => r.PageID, value); }
}
public string _consumerKey
{
get { return Retrieve(r => r._consumerKey); }
set { Store(r => r._consumerKey, value); }
}
public string _consumerSecret
{
get { return Retrieve(r => r._consumerSecret); }
set { Store(r => r._consumerSecret, value); }
}
public string access_token
{
get { return Retrieve(r => r.access_token); }
set { Store(r => r.access_token, value); }
}
public string access_token_secret
{
get { return Retrieve(r => r.access_token_secret); }
set { Store(r => r.access_token_secret, value); }
}
}
控制器:
public class SocialFeeds : Controller
{
private readonly ISocialService _socialservice;
private readonly IOrchardServices _services;
SocialFeeds(ISocialService socialservice)
{
_socialservice = socialservice;
}
SocialFeeds(ISocialService socialservice, IOrchardServices services)
{
_socialservice = socialservice;
_services = services;
}
// GET: /SocialFeeds/
public ActionResult GetFeeds() {
var feedslist =this._socialservice.getfeeds_facebook();
if (feedslist == null)
{
return this.HttpNotFound();
}
return View(feedslist);
}
public string Index()
{
var feedslist = this._socialservice.getfeeds_facebook();
return feedslist.ToString();
}
}
服务:
public interface ISocialService : IDependency
{
string getToken();
string getWebResponse(string url);
List<feed> getfeeds_facebook();
}
public class SocialService : ISocialService
{
public NewsDisplayRecord Social = new NewsDisplayRecord();
public string getToken()
{
string facebookurl = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", Social.AppID, Social.AppSecret);
return getWebResponse(facebookurl);
}
public string getWebResponse(string url)
{
WebRequest request = WebRequest.Create(url);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
return reader.ReadToEnd();
}
public List<feed> getfeeds_facebook()
{
string feedurl = string.Format("https://graph.facebook.com/{0}/feed?{1}", Social.PageID, getToken());
string output = getWebResponse(feedurl);
var converter = new ExpandoObjectConverter();
dynamic message = JsonConvert.DeserializeObject<ExpandoObject>(output, converter);
List<feed> list = new List<feed>();
foreach (var item in message.data)
{
if (item.type == "photo")
{
feed f = new feed()
{
created_time = Convert.ToDateTime(item.created_time.ToString().Replace("T", " ").Replace("+0000", "")),
icon = item.icon,
link = item.link,
message = item.message,
object_id = item.object_id,
picture = item.picture,
id = item.id,
bigpicture = string.Format("https://graph.facebook.com/{0}/picture", item.object_id)
};
f.likes = new List<user>();
foreach (var j in item.likes.data)
{
f.likes.Add(new user() { id = j.id, name = j.name });
}
list.Add(f);
}
}
return list;
}
}
}
查看:
@model NewsDisplay.Models.NewsDisplayPart
@{
var feed1 = Html.Action("GetFeeds", "SocialFeeds");
}
<fieldset>
<h1>feed1</h1>
</fieldset>