问题
I am developing an Iframe-Canvas Application.
I am using Master Page to gain permission access & display few details, that works good.
Then on content Page I want to display a textbox & linkbutton so user can post status on their wall & here I get error
(OAuthException) An active access token must be used to query information about the current user.
here's my code :
Site.master.cs
protected void Page_Load(object sender, EventArgs e)
{
var auth = new CanvasAuthorizer { Permissions = new[] { "user_about_me","user_birthday","user_location","offline_access","publish_stream" } };
if (auth.Authorize())
{
ShowFacebookContent();
}
}
private void ShowFacebookContent()
{
var fb = new FacebookWebClient();
dynamic myInfo = fb.Get("me");
lblName.Text = myInfo.name;
imgProfile.ImageUrl = "https://graph.facebook.com/" + myInfo.id + "/picture";
lblBirthday.Text = (myInfo.birthday == null ? string.Empty : DateTime.Parse(myInfo.birthday).ToString("dd-MMM-yy"));
lblHometown.Text = (myInfo.hometown.name == null ? string.Empty : myInfo.hometown.name);
lblLocation.Text = (myInfo.location.name == null ? string.Empty : myInfo.location.name);
pnlHello.Visible = true;
}
Default.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
}
public void LinkButton1_Click(object sender, EventArgs e)
{
var fb = new FacebookClient("access_token");
//var fb = new FacebookWebClient();
dynamic feedparameters = new ExpandoObject();
feedparameters.message = (message_txt.Text == null ? " " : message_txt.Text);
feedparameters.user_message_prompt = "userPrompt";
dynamic result = fb.Post("me/feed", feedparameters);
}
I am pretty new to FacebookSDK so any help will be really appreciated.
回答1:
Wel finally found what was the problem. Needed to add a hidden field.
<input type="hidden" name="signed_request" value="<%: Request.Params["signed_request"]%>"/>
I think this is neither mentioned any where in the documentation nor in the Provided Samples.
回答2:
You're not supposed to pass in "access_token" as a string value. You need to get your hands on the actual access_token value provided to you by Facebook when a user session is established, and then pass in that access_token value into the constructor.
Check out this question for more info.
来源:https://stackoverflow.com/questions/5357697/iframe-canvas-application-with-master-page