Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery Facebook墙贴在mvc中不起作用_Jquery_Asp.net Mvc_Facebook Graph Api - Fatal编程技术网

Jquery Facebook墙贴在mvc中不起作用

Jquery Facebook墙贴在mvc中不起作用,jquery,asp.net-mvc,facebook-graph-api,Jquery,Asp.net Mvc,Facebook Graph Api,我已经为facebook墙贴设置了一个facebook应用程序,将其配置为指向我的本地主机,并在facebook中创建了一个指向本地应用程序的选项卡 当我选中FacebookWebContext.Current.IsAuthenticated()时,所有操作都正常,初始加载使我的页面正常,并且用户已通过身份验证 我的问题是,当我发回数据时,Facebook上下文会丢失,FacebookWebContext.Current.IsAuthenticated()返回false 我已经在.aspx页面中

我已经为facebook墙贴设置了一个facebook应用程序,将其配置为指向我的本地主机,并在facebook中创建了一个指向本地应用程序的选项卡

当我选中
FacebookWebContext.Current.IsAuthenticated()
时,所有操作都正常,初始加载使我的页面正常,并且用户已通过身份验证

我的问题是,当我发回数据时,Facebook上下文会丢失,
FacebookWebContext.Current.IsAuthenticated()
返回false

我已经在.aspx页面中检查了相同的代码;它运行良好,但同样的代码在mvc应用程序中不起作用

下面是我的代码

查看

 <input  value="Facebook Wall Posting" onclick="FacebookWall()" type="button" />

<script>
 function fbAction()
           {
                var fbid=$('#txtFBID').val(); 
                var url = "http://www.facebook.com/dialog/friends/?id=" + fbid + "&app_id=244816449015123&redirect_uri=http://localhost:15995/Saloon/CustomerPost";
                location.href = url;
            }        
            function FacebookWall() {
                $.ajax({
            type: "POST",
            url: '@Url.Action("FacebookWall", "Saloon")',
        contentType: "application/json; charset=utf-8",
        //data: { FacebookId: $('#txtFBID').val() },
        dataType: "json",
        success: function() { }

    });
            } 
</script>

函数fbAction()
{
var fbid=$('#txtFBID').val();
变量url=”http://www.facebook.com/dialog/friends/?id=“+fbid+”&应用程序id=244816449015123&重定向uri=http://localhost:15995/Saloon/CustomerPost";
location.href=url;
}        
函数FacebookWall(){
$.ajax({
类型:“POST”,
url:'@url.Action(“FacebookWall”、“Saloon”),
contentType:“应用程序/json;字符集=utf-8”,
//数据:{FacebookId:$('#txtFBID').val(),
数据类型:“json”,
成功:函数(){}
});
} 
控制器

[HttpPost]
    public ActionResult FacebookWall()
    {
        string app_id = "34567777771276071";
        string app_secret = "8466bc130961b988367f40f2234f34r4";
        string scope = "publish_stream,manage_pages";

        if (Request["code"] == null)
        {
            Response.Redirect(string.Format(
                "https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}",
                app_id, Request.Url.AbsoluteUri, scope));
        }
        else
        {
            Dictionary<string, string> tokens = new Dictionary<string, string>();

            string url = string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}",
                app_id, Request.Url.AbsoluteUri, scope, Request["code"].ToString(), app_secret);

            HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;

            using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                StreamReader reader = new StreamReader(response.GetResponseStream());

                string vals = reader.ReadToEnd();

                foreach (string token in vals.Split('&'))
                {
                    //meh.aspx?token1=steve&token2=jake&...
      tokens.Add(token.Substring(0, token.IndexOf("=")),
          token.Substring(token.IndexOf("=") + 1, token.Length -                                                   token.IndexOf("=") - 1));
                }
            }

            string access_token = tokens["access_token"];

            string fil = Server.MapPath("Images/2921-large-apple-icon-png-1.jp");
            var client = new FacebookClient(access_token);

            dynamic parameters = new ExpandoObject();
            parameters.message = "Check out this funny article";
            parameters.link = "http://www.natiska.com/article.html";
            parameters.picture = "http://www.natiska.com/dav.png";
            parameters.name = "Article Title";
            parameters.caption = "Caption for the link";

           client.Post("/me/feed", parameters);


        }
        return View();
         }
[HttpPost]
公共行动结果FacebookWall()
{
字符串app_id=“345677771276071”;
字符串app_secret=“8466bc130961b988367f40f2234f34r4”;
string scope=“发布\u流,管理\u页面”;
如果(请求[“代码”]==null)
{
重定向(string.Format(
"https://graph.facebook.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}“,
app_id,Request.Url.AbsoluteUri,scope));
}
其他的
{
字典标记=新字典();
字符串url=string.Format(“https://graph.facebook.com/oauth/access_token?client_id={0}&redirect_uri={1}&scope={2}&code={3}&client_secret={4}”,
app_id,Request.Url.AbsoluteUri,作用域,Request[“code”]。ToString(),app_secret);
HttpWebRequest-request=WebRequest.Create(url)为HttpWebRequest;
使用(HttpWebResponse=request.GetResponse()作为HttpWebResponse)
{
StreamReader=新的StreamReader(response.GetResponseStream());
字符串vals=reader.ReadToEnd();
foreach(vals.Split('&')中的字符串标记)
{
//meh.aspx?token1=steve&token2=jake&。。。
tokens.Add(token.Substring(0,token.IndexOf(“=”)),
子字符串(token.IndexOf(“=”)+1,token.Length-token.IndexOf(“=”-1));
}
}
字符串访问令牌=令牌[“访问令牌”];
string fil=Server.MapPath(“Images/2921-large-apple-icon-png-1.jp”);
var client=新的FacebookClient(访问令牌);
动态参数=新的ExpandooObject();
parameters.message=“查看这篇有趣的文章”;
parameters.link=”http://www.natiska.com/article.html";
参数。图片=”http://www.natiska.com/dav.png";
parameters.name=“文章标题”;
parameters.caption=“链接的标题”;
client.Post(“/me/feed”,参数);
}
返回视图();
}

请不要将“ASP.NET MVC”简单地称为“MVC”。一个是框架,另一个是独立于语言的设计模式。就像把IE叫做“互联网”好吧你知道我的问题吗