Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/310.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
C#,找不到与oAuth和facebook服务器端登录进程一起工作的UrlEncoder_C#_Facebook_Facebook Graph Api_Oauth_Urlencode - Fatal编程技术网

C#,找不到与oAuth和facebook服务器端登录进程一起工作的UrlEncoder

C#,找不到与oAuth和facebook服务器端登录进程一起工作的UrlEncoder,c#,facebook,facebook-graph-api,oauth,urlencode,C#,Facebook,Facebook Graph Api,Oauth,Urlencode,我正在尝试在我的C#MVC应用程序中使用facebook进行服务器端登录 在我的应用程序中提交状态更新时,它必须将其发布到facebook上,我重定向到: https://www.facebook.com/dialog/oauth?client_id={0}&scope={1}&redirect_uri={2} 使用此方法: Response.Redirect(...); using (var wc = new WebClient()){ wc.Download

我正在尝试在我的C#MVC应用程序中使用facebook进行服务器端登录

在我的应用程序中提交状态更新时,它必须将其发布到facebook上,我重定向到:

https://www.facebook.com/dialog/oauth?client_id={0}&scope={1}&redirect_uri={2}
使用此方法:

Response.Redirect(...);
 using (var wc = new WebClient()){
      wc.DownloadString(...)
 }
其中我的重定向uri编码如下:

HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
 HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
然后返回到我的MVC应用程序(在接受fb权限后),getAuthToken操作向URI发出请求:

 https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&code={2}&redirect_uri={3}
使用此方法:

Response.Redirect(...);
 using (var wc = new WebClient()){
      wc.DownloadString(...)
 }
其中我的重定向uri再次编码如下:

HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
 HttpUtility.UrlEnconde("http://local.mydomain.com/getAuthToken?message=the original message");
如果“原始消息”不包含空格,则它可以工作,但当我开始添加空格和其他特殊字符时,我得到一个OAuth异常:

验证验证代码时出错

所以我的问题是,我应该使用什么样的URL编码才能使其正常工作


我发现了一些东西,但是我得到了相同的错误,我不知道我是否需要一个特殊的方法来进行重定向,或者我是否需要对这两个请求使用不同的编码。

我建议您看看Dino Cheisa优秀的OAuth.Manager类。这会正确地进行URL编码。你可以从

中得到它来解决这个问题,我用它来编码:

static public string EncodeTo64(string toEncode)
  {
     byte[] toEncodeAsBytes
           = Encoding.ASCII.GetBytes(toEncode);
     string returnValue
           = Convert.ToBase64String(toEncodeAsBytes);
     return returnValue;
  }
这是要解码的

  static public string DecodeFrom64(string encodedData)
  {
     byte[] encodedDataAsBytes
         = Convert.FromBase64String(encodedData);
     string returnValue =
        Encoding.ASCII.GetString(encodedDataAsBytes);
     return returnValue;
  }
万一有人需要它 塔克斯