错误:CanvasAuthorizer.Authorize()始终返回false

时间:2011-11-20 05:54:02

标签: c# facebook sdk authorization facebook-canvas

我正在使用来自Facebook C#SDK的示例。每次运行代码CanvasAuthorizer.Authorize()时,它总是返回false。我在app_id文件中指定了web.config和密钥。并且还有扩展许可。

<add key="extendedPermissions" value="user_about_me,publish_stream"/>

这是我的代码:

public partial class MForm : System.Web.UI.Page
{
    private CanvasAuthorizer _canvasAuthorizer;
    protected CanvasAuthorizer CanvasAuthorizer
    {
        get
        {
            if (_canvasAuthorizer == null)
            {
                var extendedPermissions = ConfigurationManager.AppSettings["extendedPermissions"].Split(',');
                _canvasAuthorizer = new CanvasAuthorizer();
            }
            return _canvasAuthorizer;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (CanvasAuthorizer.Authorize())
        {
            var fb = new FacebookWebClient();
            dynamic me = fb.Get("me");

            imgProfilePic.ImageUrl = string.Format("https://graph.facebook.com/{0}/picture", me.id);

            lblName.Text = me.name;
            lblFirstName.Text = me.first_name;
            lblLastName.Text = me.last_name;
        }
        else
        {

        }
    }

    protected void btnPostToWall_Click(object sender, EventArgs e)
    {
        if (CanvasAuthorizer.Authorize())
        {
            var fb = new FacebookWebClient();

            dynamic parameters = new ExpandoObject();
            parameters.message = txtMessage.Text;

            try
            {
                dynamic id = fb.Post("me/feed", parameters);
                lblPostMessageResult.Text = "Message posted successfully";
                txtMessage.Text = string.Empty;
            }
            catch (FacebookApiException ex)
            {
                lblPostMessageResult.Text = ex.Message;
            }
        }
    }
}

0 个答案:

没有答案