Facebook C#SDK 4.2.1发布在墙上的问题

时间:2011-01-30 12:25:14

标签: facebook facebook-c#-sdk oauth-2.0

您好我尝试在用户墙上发布内容时遇到问题。这是我的代码

 protected void Page_Load(object sender, EventArgs e)
{       
        app = new FacebookApp();
        auth = new CanvasAuthorizer(app);
    auth.Perms += "user_about_me,publish_stream,create_event,offline_access";
    if (auth.IsAuthorized())
    {
        Response.Write("authorized    " + app.Session.UserId.ToString()+"  "+app.Session.AccessToken + "<br/>");
        dynamic rez = app.Get("me");
        Response.Write(rez.first_name + "  "+rez.last_name);
    }
    else
        Response.Write("not authorized    ");      
}
protected void btnPost_Click(object sender, EventArgs e)
{
    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 = app.Api("/me/feed",parameters);
}

当我尝试发布时,我得到了:

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

描述:执行当前Web请求期间发生了未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。

异常详细信息:Facebook.FacebookOAuthException:(OAuthException)必须使用活动访问令牌来查询有关当前用户的信息。

P.S。

dynamic rez = app.Get("me");
        Response.Write(rez.first_name + "  "+rez.last_name); 

没有问题!

提前致谢。

1 个答案:

答案 0 :(得分:3)

那是因为你没有给它访问令牌试试

FacebookApp app = new FacebookApp("my_access_token");

在帖子按钮事件的顶部并替换

dynamic result = app.Api("/me/feed",parameters);

dynamic result = app.Post("me/feed", parameters);