0

I am trying to develop a demo Facebook App in C#. But I could not get Access Token (for both Application & User).

Please help me, How could I get this for both Application & User (Diff examples are welcome).

My Code is:

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");
        }
    }
}

Well When I check the code by putting the break points, I found that if (fbWebContext.IsAuthorized()) is always returns false, If I try to comment the Authorization I get the following Exception:

(OAuthException) An active access token must be used to query information about the current user.

Than I searched for this, I got following Link: Another Question Link

But When I got the Access Token for the App, I could not assign to the object as that is readonly.

What should I Do in this case, Also How do I get Access Token for Users?

Thanks

4

1 回答 1

0

您需要在facebookDeveloperSite创建一个新的应用程序和帐户

您将从那里获得访问令牌

问候

于 2012-12-13T09:45:13.037 回答