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
facebook访问令牌400错误请求_Facebook_Authentication_Facebook Oauth - Fatal编程技术网

facebook访问令牌400错误请求

facebook访问令牌400错误请求,facebook,authentication,facebook-oauth,Facebook,Authentication,Facebook Oauth,我使用以下代码检索facebook accessToken string url = "https://graph.facebook.com/oauth/access_token?" + "client_id={0}" + "&redirect_uri={1}" + "&client_secret={2}" +

我使用以下代码检索facebook accessToken

string url = "https://graph.facebook.com/oauth/access_token?" +
                         "client_id={0}" +
                         "&redirect_uri={1}" +
                         "&client_secret={2}" +
                         "&code={3}";
            url = string.Format(url, clientId, redirectUri.EncodeUrl(), clientSecret, code);
            //Create a webrequest to perform the request against the Uri
            WebRequest request = WebRequest.Create(url);
            try
            {
                //read out the response as a utf-8 encoding and parse out the access_token
                using (WebResponse response = request.GetResponse())
                {
                    using (Stream stream = response.GetResponseStream())
                    {
                        //string urlRedirects = response.ResponseUri.ToString();
                        Encoding encode = Encoding.GetEncoding("utf-8");
                        if (stream != null)
                        {
                            StreamReader streamReader = new StreamReader(stream, encode);
                            string accessToken = streamReader.ReadToEnd().Replace("access_token=", "");
                            streamReader.Close();
                            response.Close();
                            return accessToken;
                        }
                    }
                }
            }
            catch
            {
                return null;
            }
然而,我经常收到这个模棱两可的错误信息

{
"error": {
"message": "Error validating verification code.",
"type": "OAuthException",
"code": 100
}
}
我检查了代码100“无效参数”对我来说没有多大意义


有人遇到过类似的问题吗?

您需要将用户发送到Facebook登录页面以获取有效的
代码。然后,应使用该代码为用户获取
访问\u令牌

遵循规则

  • 检查您在url中添加的代码是否正确 比如说

    http://www.xyz.com/?code=AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20#_=_
    
  • 代码必须是

        code = AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20
    
    代码最后不应包括以下内容

        #_=_ 
    
    如果上面没有解决问题


    2。重定向uri必须以结尾/

    redirect_uri=http://www.xyz.com/
    
    下面给出了上面提到的一些错误

    redirect_uri=http://www.xyz.com
    

    3.还要确保 Facebook上的应用程序和登录Facebook的网站设置了相同的地址
    e、 g

    我还收到了错误消息400,当时我的应用程序id和机密出错(我把开发和生产id-s和机密搞乱了)


    修复它们(还要注意正确的主机)为我解决了这个问题

    试试这个:@Thomas,不幸的是,我在前面的代码中已经遇到了不同的问题。“代码”部分正在工作。正如我所说,当我请求身份验证令牌时,400错误请求会发生。错误表明代码有问题,因此请确保代码没有被修改或更改。这可能是问题的原因。+1从否决票中恢复过来。尽管这并没有解决问题,但仍然不值得投反对票。它可能会帮助其他人。哇,我也有同样的问题(没有尾随斜杠)。很难相信,如果忽略了错误请求,您会得到错误响应400。没有尾随斜杠对我没有影响。