开发者

C# equivalent of file_get_contents (PHP)

开发者 https://www.devze.com 2023-03-06 09:56 出处:网络
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

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开发者_如何学Python 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...


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:

string test;
string[] lines = test.Split('\n');


To use oauth/access_token or any methods related to oauth stuffs use FacebookOAuthClient not FacebookClient or FacebookClient.

FacebookOAuthClient.GetApplicationAccessToken(..)
FacebookOAuthClient.ExchangeCodeForAccessToken(..)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号