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.
我希望我能工作:
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/59926.html下一篇: sdk:张贴在用户的墙上