作为 (OAuthException) (#15) The method you are calling must be called with an app secret signed session 的后续行动我想知道 file_get_contents() 的等效项是什么。我尝试了以下操作,但出现路径中存在非法字符
错误。
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 下载文本。 WebClient 还supports authentication .
此外,要将字符串拆分为可以使用的行:
string test;
string[] lines = test.Split('\n');
关于C# 相当于 file_get_contents (PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6037356/