C# equivalent of file_get_contents (PHP)
本文关键字:PHP contents get of file equivalent | 更新日期: 2023-09-27 17:57:00
作为 (OAuthException) (#15) 的后续 必须使用应用程序机密签名会话调用要调用的方法 我想知道 file_get_contents() 的等价物是什么。我尝试了以下内容,但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)
,但遇到了同样的错误。我能做些什么吗?
我什至不确定它会起作用,但至少我可以尝试......
您可以使用
WebClient.DownloadString
从URL下载文本。网络客户端还支持身份验证。
此外,要将字符串拆分为行,您可以使用:
string test;
string[] lines = test.Split(''n');
要使用 oauth/access_token 或任何与 oauth 内容相关的方法,请使用 FacebookOAuthClient 而不是 FacebookClient 或 FacebookClient。
FacebookOAuthClient.GetApplicationAccessToken(..)
FacebookOAuthClient.ExchangeCodeForAccessToken(..)