开发者

facebook-c#-sdk: Posting on user's wall

Hi I'm still learning Facebook C# SDK 5.0.3, I`m building a facebook Apps(iFrame). I follow the sample that was attached on the SDK. I successfully run it and I want to extend it by creating a button event that every time the user click the button a "Hello World" will posted to his wall. Here's the code;

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

After running this code i`m getting this error

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

Please note that on my page_load event I can successfully get the user name using the sample on the Sdk package,

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

    }
}

I suspect that i'm not getting the right access token for my button event.


I hope that i works :

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


The ordinary access token will expire after certain minutes.I think your access token has expired before you call the post event.You can renew your access token and then continue

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜