开发者

Facebook C# SDK 4.2.1 posting on wall problem

Hello i have a problem when i try to post something on users wall. here is my code

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

when i try to post i get the :

(OAuthException) An active access token must be used to query information about the curr开发者_JS百科ent user.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: Facebook.FacebookOAuthException: (OAuthException) An active access token must be used to query information about the current user.

P.S.

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

is working with no problems!

Thanks in advance.


That is because you have not given it access token try putting

FacebookApp app = new FacebookApp("my_access_token");

at top of post button event and replace

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

with

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜