C#等价于file_get_contents(PHP)

作为(OAuthException)的后续(#15)您调用的方法必须使用app secret signed session调用我想知道file_get_contents()的等价物。 我尝试了以下但我illegal characters in path错误中得到了illegal characters in path

  public ActionResult About() { var fb = new FacebookWebClient(FacebookWebContext.Current); var tokenUrl = "https://graph.facebook.com/oauth/access_token?client_id=" + FacebookWebContext.Current.Settings.AppId + "&client_secret=" + FacebookWebContext.Current.Settings.AppSecret + "&grant_type=client_credentials"; var objReader = new StreamReader(tokenUrl); string sLine = ""; var arrayList = new ArrayList(); while (sLine != null) { sLine = objReader.ReadLine(); if (sLine != null) arrayList.Add(sLine); } objReader.Close(); var appToken = arrayList.ToString(); dynamic result = fb.Post(string.Format("{0}/accounts/test-users", FacebookWebContext.Current.Settings.AppId), new { installed = false, permissions = "read_stream", access_token = appToken }); return Content(result.ToString()); } 

我也尝试了System.IO.File.ReadAllText(tokenUrl) ,我得到了同样的错误。 有什么我可以做的吗?

我甚至不确定它会起作用,但至少我可以尝试……

要使用oauth / access_token或任何与oauth相关的方法,请使用FacebookOAuthClient而不是FacebookClient或FacebookClient。

 FacebookOAuthClient.GetApplicationAccessToken(..) FacebookOAuthClient.ExchangeCodeForAccessToken(..) 

您可以使用WebClient.DownloadString从URL下载文本。 WebClient还支持身份validation 。

另外,要将字符串拆分为行,您可以使用:

 string test; string[] lines = test.Split('\n');