C# 相当于 file_get_contents (PHP)
作为 (OAuthException) (#15) 您调用的方法必须使用应用程序秘密签名会话来调用 我想知道 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) ,但遇到了同样的错误。有什么我可以做的吗?
我什至不确定它是否会起作用,但至少我可以尝试......
As a follow-up to (OAuthException) (#15) The method you are calling must be called with an app secret signed session I want to know what is the equivalent of file_get_contents(). I tried the following but I got illegal characters in path
error.
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());
}
I also tried System.IO.File.ReadAllText(tokenUrl)
and I got the same error. Is there anything I can do?
I'm not even sure it's going to work, but at least I can try...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
WebClient.DownloadString
进行下载来自 URL 的文本。 WebClient 还支持身份验证。另外,要将字符串分成几行,您可以使用:
You can use
WebClient.DownloadString
to download text from a URL. The WebClient also supports authentication.Also, to split your string into lines you can use:
要使用 oauth/access_token 或任何与 oauth 相关的方法,请使用 FacebookOAuthClient 而不是 FacebookClient 或 FacebookClient。
To use oauth/access_token or any methods related to oauth stuffs use FacebookOAuthClient not FacebookClient or FacebookClient.