我正在尝试用C#开发一个演示Facebook App。但我无法获得访问令牌(适用于应用程序和用户)。
请帮助我,我怎么能同时获得这个应用程序&用户(欢迎使用Diff示例)。
我的代码是:
public partial class _Default : Page
{
protected void Page_Load(object sender, EventArgs e)
{
CheckIfFacebookAppIsSetupCorrectly();
var fbWebContext = FacebookWebContext.Current;
if (fbWebContext.IsAuthorized())
{
var fb = new FacebookWebClient(fbWebContext);
dynamic result = fb.Get("/me");
lblName.Text = "Hi " + result.name;
}
}
private void CheckIfFacebookAppIsSetupCorrectly()
{
bool isSetup = false;
var settings = ConfigurationManager.GetSection("facebookSettings");
if (settings != null)
{
var current = settings as IFacebookApplication;
if (current.AppId != "{app id}" &&
current.AppSecret != "{app secret}")
{
isSetup = true;
}
}
if (!isSetup)
{
System.Web.HttpContext.Current.Response.Redirect("~/GettingStarted.aspx");
}
}
}
当我通过输入断点来检查代码时,我发现 if(fbWebContext.IsAuthorized())总是返回false,如果我尝试对Authorization进行注释,我会得到以下异常:
我搜索了这个,我得到了以下链接:Another Question Link
但是当我获得应用程序的访问令牌时,我无法分配给该对象,因为它是只读的。
在这种情况下我该怎么做,另外我如何获得用户的访问令牌?
由于