Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.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
使用DotNetOpenAuth进行facebook长期访问_Facebook_Facebook Graph Api_Dotnetopenauth - Fatal编程技术网

使用DotNetOpenAuth进行facebook长期访问

使用DotNetOpenAuth进行facebook长期访问,facebook,facebook-graph-api,dotnetopenauth,Facebook,Facebook Graph Api,Dotnetopenauth,我正在asp.net中创建一个应用程序,它将使用用户的facebook数据,并使用其api, 但是为了访问FBAPI,我们需要首先执行OAuth2.0。 我也通过在以下代码中使用DotNetOpenAuth库实现了这一点: private static readonly FacebookClient client = new FacebookClient { ClientIdentifier = ConfigurationManager.AppSettings["fbAp

我正在asp.net中创建一个应用程序,它将使用用户的facebook数据,并使用其api, 但是为了访问FBAPI,我们需要首先执行OAuth2.0。 我也通过在以下代码中使用DotNetOpenAuth库实现了这一点:

private static readonly FacebookClient client = new FacebookClient
    {
        ClientIdentifier = ConfigurationManager.AppSettings["fbAppID"],
        ClientCredentialApplicator = ClientCredentialApplicator.PostParameter(ConfigurationManager.AppSettings["fbSecret"]),
    };

    protected void Page_Load(object sender, EventArgs e)
    {
        IAuthorizationState authorization = client.ProcessUserAuthorization();
        if (authorization == null)
        {
            // Kick off authorization request
            client.RequestUserAuthorization();                
        }
        else
        {
            var req = WebRequest.Create("https://graph.facebook.com/oauth/access_token?client_id=" + ConfigurationManager.AppSettings["facebookAppID"] + "&client_secret=" + ConfigurationManager.AppSettings["facebookAppSecret"] + "&grant_type=fb_exchange_token&fb_exchange_token=" + Uri.EscapeDataString(authorization.AccessToken));


            var request = WebRequest.Create("https://graph.facebook.com/me?access_token=" + Uri.EscapeDataString(authorization.AccessToken));
            using (var response = request.GetResponse())
            {
                using (var responseStream = response.GetResponseStream())
                {
                    var graph = FacebookGraph.Deserialize(responseStream);
                    this.nameLabel.Text = HttpUtility.HtmlEncode(graph.Name);
                }
            }
        }
    }
我这里的问题是,我如何使用DotNetOpenAuth库获得facebook的长期访问令牌,这样用户就不需要反复登录,我可以将其存储在某个地方。
请帮助我。

如果可能,请使用Facebook SDK for.Net创建长时间访问令牌。可能是60天

使用Facebook

var cl=新FacebookClientshort\u lived\u access\u令牌

            dynamic result = client.Post("oauth/access_token", new
            {
                client_id = "your app id",
                client_secret = "your app secret",
                grant_type = "fb_exchange_token",
                fb_exchange_token = client.AccessToken
            });

var long_live_access_token=result.access_token

我也向这个url发送了一个请求:+ConfigurationManager.AppSettings[fbAppID]+&client\u secret=+ConfigurationManager.AppSettings[fbAppSecret]+&grant\u type=fb\u exchange\u token&fb\u exchange\u token=+Uri.EscapeDataStringauthorization.AccessToken,但我收到了一个错误,即无效字符“a”,这很奇怪
            dynamic result = client.Post("oauth/access_token", new
            {
                client_id = "your app id",
                client_secret = "your app secret",
                grant_type = "fb_exchange_token",
                fb_exchange_token = client.AccessToken
            });