C# 相当于 file_get_contents (PHP)

标签 c# facebook facebook-c#-sdk inputstream

作为 (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/

相关文章:

facebook - 无法从 facebook OAuth 获取所有电子邮件

facebook - 从 Facebook 保存 accessToken,但它会重置

.net - Facebook 和 asp.net 成员(member)资格的整合

c# - 无法加载 DLL(找不到模块 HRESULT : 0x8007007E)

c# - 有没有办法通过读取图像标题来了解 png 图像的透明度?

ios - Facebook iOS SDK 4 的 FBFriendPickerViewController 替换

android - proguard 的 Xamarin facebook 分支无法访问 .jar

c# - 获取 Facebook 的应用程序访问 token

c# - Autocompletebox 不清除键盘笔画

c# - 自定义日历控件