Search code examples
c#xamarin.androidhttpwebrequestreddit

Reddit GET returns 403 even though the token is correct


I'm trying to interface with Reddit API, but running into some issues on the GET after retrieving my access_token. I have confirmed the token and required scopes to complete this operation:

        Android.Widget.Toast.MakeText(this, "TOKEN : " + myItem.myAccessKey.accessKeyString, ToastLength.Long).Show();
        HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("https://www.reddit.com/api/v1/me");
        myRequest.PreAuthenticate = true;
        myRequest.Headers.Add("Authorization", "Bearer " + myItem.myAccessKey.accessKeyString);
        var myResponse = myRequest.GetResponse(); //403 forbidden here
        if (myResponse == null)
        {
            Finish();
        }
        var myStreamReader = new StreamReader(myResponse.GetResponseStream());
        var json = myStreamReader.ReadToEnd();
        myResponse.Close();
        myStreamReader.Close();

Solution

  • 403 means Forbidden. Authentication succeeded, ie the token and headers are correct, but you don't have permission to GET the URL you typed, https://www.reddit.com/api/v1/me