[英]C# equivalent of file_get_contents (PHP)
作为(OAuthException)(#15)的跟进, 必须使用应用程序秘密签名的会话调用正在调用的方法,我想知道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)
,但遇到了同样的错误。 有什么我可以做的吗?
我什至不确定它是否会起作用,但至少我可以尝试...
您可以使用WebClient.DownloadString
从URL下载文本。 WebClient还支持身份验证 。
另外,要将您的字符串分成几行,您可以使用:
string test;
string[] lines = test.Split('\n');
要使用oauth / access_token或与oauth内容相关的任何方法,请使用FacebookOAuthClient而不是FacebookClient或FacebookClient。
FacebookOAuthClient.GetApplicationAccessToken(..)
FacebookOAuthClient.ExchangeCodeForAccessToken(..)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.