我在MasterPage Facebook应用程序的ContentPage中收到错误“对象引用未设置为对象的实例”。
Site.master.cs
public FacebookSession CurrentSession
{
get { return (new CanvasAuthorizer()).Session; }
}
protected void Page_Load(object sender, EventArgs e)
{
var auth = new CanvasAuthorizer { Perms = "email,read_stream,publish_stream,offline_access,user_about_me" };
if (auth.Authorize())
{
ShowFacebookContent();
}
}
private void ShowFacebookContent()
{
var fb = new FacebookClient(this.CurrentSession.AccessToken);
dynamic myInfo = fb.Get("me");
lblName.Text = myInfo.name;
imgProfile.ImageUrl = "https://graph.facebook.com/" + myInfo.id + "/picture";
lblBirthday.Text = myInfo.birthday;
pnlHello.Visible = true;
}
这个主页工作正常&显示UserName& ProfilePic。
Default.aspx.cs
SiteMaster myMasterPage;
protected void Page_Load(object sender, EventArgs e)
{
myMasterPage = this.Page.Master as SiteMaster;
}
public void LinkButton1_Click(object sender, EventArgs e)
{
var fb = new FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
dynamic feedparameters = new ExpandoObject();
feedparameters.message = (message_txt.Text == null ? " " : message_txt.Text);
feedparameters.user_message_prompt = "userPrompt";
/*Dictionary<string, object> feedparameters = new Dictionary<string, object>();
feedparameters.Add("message", "Testing Application");
feedparameters.Add("user_message_prompt", "Post To Your Wall");
feedparameters.Add("display", "iframe");*/
dynamic result = fb.Post("me/feed", feedparameters);
}
即使这个页面加载正常,但当我尝试使用LinkButton发布时出现问题。 以下行给出了错误。
var fb =新FacebookClient(this.myMasterPage.CurrentSession.AccessToken);
On LinkButton Click Object Reference未设置为对象的实例...
我真的很感激一些帮助。
答案 0 :(得分:0)
Wel终于找到了问题所在。需要添加隐藏字段。
<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>
我认为在文档和提供的样本中都没有提及任何内容。