重复Facebook帖子投掷错误(错误请求)c#mvc

时间:2014-02-17 09:52:17

标签: c# jquery asp.net-mvc facebook facebook-graph-api

我正在研究c#mvc4项目。我正试图通过我的网站向Facebook发布消息,链接,图像和视频。我按照本教程http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API.I成功进行首次发布,其次发布时抛出代码上的错误请求(400)

  facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());

我的代码段在这里

控制器

        Authentication auth = new Authentication();


    public ActionResult Success()
    {

      if (Request.QueryString["code"] != null)
            {
                string Code = Request.QueryString["code"];
                Session["facebookQueryStringValue"] = Code;
            }
            if (Session["facebookQueryStringValue"] != null)
            {

                Facebook facebook = auth.FacebookAuth();
                facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());
                FBUser currentUser = facebook.GetLoggedInUserInfo();
                IFeedPost FBpost = new FeedPost();
                if (Session["postStatus"].ToString() != "")
                {
                    FBpost.Message = Session["postStatus"].ToString();
                    facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
                    //return RedirectToAction("Index");
                }

            }

        return View();
    }

    public JsonResult PostStatus(string msg)
    {
        Session["postStatus"] = msg;


        Facebook facebook = auth.FacebookAuth();
        if (Session["facebookQueryStringValue"] == null)
        {
            string authLink = facebook.GetAuthorizationLink();
            return Json(authLink);
        }

        if (Session["facebookQueryStringValue"] != null)
        {     

            facebook.GetAccessToken(Session["facebookQueryStringValue"].ToString());
            FBUser currentUser = facebook.GetLoggedInUserInfo();                
            IFeedPost FBpost = new FeedPost();
            if (Session["postStatus"].ToString() != "")
            {
                FBpost.Message = Session["postStatus"].ToString();
                facebook.PostToWall(currentUser.id.GetValueOrDefault(), FBpost);
                Session["facebookQueryStringValue"] = "";
            }
        }
        return Json("No"); 
    }

验证

 public class Authentication
{
    public Facebook FacebookAuth()
    {
//Setting up the facebook object
        Facebook facebook = new Facebook();
        facebook.AppID = "xxxxxxxxxxxxxxxxxxx";
        facebook.CallBackURL = "http://localhost:8088/PostStatus/Success";
        facebook.Secret = "xxxxxxxxxxxxxxxxxxx";

        //Setting up the permissions
        List<FBPermissions> permissions = new List<FBPermissions>() {
            FBPermissions.user_about_me, // to read about me               
            FBPermissions.user_events,
            FBPermissions.user_status,
            FBPermissions.read_stream,
            FBPermissions.friends_events,
            FBPermissions.publish_stream
        };

        //Pass the permissions object to facebook instance
        facebook.Permissions = permissions;
        return facebook;
    }
}

调用Ajax

 $.ajax({
                url: '/PostStatus/PostStatus',
                type: 'POST',
                data: { msg: msg },
                success: function (authLink) {
                    if (authLink != 'No') {
                        // window.open(authLink, 'title', 'width=660,height=500,status=no,scrollbars=yes,toolbar=0,menubar=no,resizable=yes,top=60,left=320');
                        window.location.href = authLink;
                    }
                }
            });

任何关于此错误的帮助都是值得的。我无法看到任何其他教程在c#mvc4上在facebook上发布消息,链接,视频和图像

0 个答案:

没有答案