sdk:张贴在用户的墙上

嗨,我还在学习Facebook C# SDK 5.0.3 ,我正在构建一个Facebook应用程序(iFrame)。 我遵循SDK上附加的示例。 我成功运行它,我想通过创建一个按钮事件来扩展它,每次用户单击按钮时,“Hello World”都会发布到他的墙上。 这是代码;

protected void btnRegister_Click(object sender, EventArgs e)
{
    try
    {


        var fbApp = new FacebookClient(FacebookContext.Current);
        dynamic result = fbApp.Post("/me/feed", new Dictionary<string, object> { { "message", "Hello World" } });


    }

    catch (Exception ex)
    {
        Response.Write(ex.ToString());
        Msg.Text = "An error may occurred while processing your request, you may try again.";
    }
}

运行这段代码后,我得到这个错误

(OAuthException)(OAuthException)必须使用活动访问令牌来查询有关当前用户的信息。

请注意,在我的page_load事件中,我可以使用Sdk包中的示例成功获取用户名,

public FacebookSession CurrentSession
{
    get { return (new CanvasAuthorizer()).Session; }
}

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        //Response.Redirect("Registration-Closed.aspx");
        Panel1.Visible = true;
        Panel2.Visible = false;


        var auth = new CanvasAuthorizer { Perms = "user_about_me,publish_stream,offline_access" };

        if (auth.Authorize())
        {
            ShowFacebookContent();
        }

    }
}

我怀疑我没有为我的按钮事件获取正确的访问令牌。


我希望我能工作:

var client = new FacebookClient("my_access_token");
dynamic parameters = new ExpandoObject();
parameters.message = "Check out this funny article";
parameters.link = "http://www.example.com/article.html";
parameters.picture = "http://www.example.com/article-thumbnail.jpg";
parameters.name = "Article Title";
parameters.caption = "Caption for the link";
parameters.description = "Longer description of the link";
parameters.actions = new {
    name = "View on Zombo",
    link = "http://www.zombo.com",
};
parameters.privacy = new {
    value = "ALL_FRIENDS",
};
parameters.targeting = new {
    countries = "US",
    regions = "6,53",
    locales = "6",
};
dynamic result = client.Post("me/feed", parameters);

普通访问令牌将在某些分钟后过期。我认为您的访问令牌在您致电后事件之前已过期。您可以续订您的访问令牌,然后继续

链接地址: http://www.djcxy.com/p/59925.html

上一篇: sdk: Posting on user's wall

下一篇: Email API service with Sendgrid like API endpoints and Mailchimp like dashboard