samedi 4 mars 2017

Am I getting a token in the correct way?

I've been converting some code from Java to Unity's C# and can't figure out what I'm supposed to do for the "parameters" field. The goal is to get an access token from Reddit, but the www class' second field requires a byte array but I think I need it to take my parameters including the uuid in order to get the token. Right now the only error is for Encoding.UTF8.GetBytes(parameters) where "parameters" is of the wrong type. Encoding.UTF8.GetBytes() takes a char[] array or string but I think he main problem in the code is how I'm going about this. Am I getting the token in the correct way?

        String basicAuth = "Basic " + Base64Encode(key);

        Dictionary<string, string> headers = new Dictionary<string, string>();
        headers.Add("User-Agent", "desktop:MemeBroker:v1.0 (by /u/ImTheTechn0mancer)");
        headers.Add("Authorization", basicAuth);

        Dictionary<string, string> parameters = new Dictionary<string, string>();
        parameters.Add("grant_type", "http://ift.tt/1JOIRx6");
        parameters.Add("device_id", uuid);

        WWW www = new WWW(tokenURL, Encoding.UTF8.GetBytes(parameters), headers); //this is where the error is
        StartCoroutine(WaitForRequest(www));




Aucun commentaire:

Enregistrer un commentaire