Question

I'm trying to implement the OAuth using a simple class but I'm getting an error

public OAuthResponse AcquireRequestToken(string uri, string method) 
{ 
    NewRequest(); 
    var authzHeader = GetAuthorizationHeader(uri, method); 

    // prepare the token request 
    var request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(uri); 
    request.Headers.Add("User-Agent", "MyAppId/1.0.3 +http://example.pt/"); 
    request.Headers.Add("Authorization", authzHeader); 
    request.Method = method; 
    request.ContentLength = 0; 

    using (var response = (System.Net.HttpWebResponse)request.GetResponse()) 
    { 
        using (var reader = new System.IO.StreamReader(response.GetResponseStream())) 
        { 
            var r = new OAuthResponse(reader.ReadToEnd()); 
            this["token"] = r["oauth_token"]; 

            // Sometimes the request_token URL gives us an access token, 
            // with no user interaction required. Eg, when prior approval 
            // has already been granted. 
            try 
            { 
                if (r["oauth_token_secret"] != null) 
                this["token_secret"] = r["oauth_token_secret"]; 
            } 
            catch { } 
            return r; 
        } 
    } 
} 

The error it's in this line

var response = (System.Net.HttpWebResponse)request.GetResponse()

and the error is

Aditional information: The remote server returned an error: (403) Forbidden.

Any Help? Here is the full OAuth class https://cropperplugins.codeplex.com/SourceControl/changeset/view/65377#1710422

Also the service that i'm trying to access it's Discogs.com API DOCS: http://www.discogs.com/developers

UPDATE 1

I've added the user-agent header the discogs Staff said it was needed but now I have another error on the User-Agent line request.Headers.Add("User-Agent", "BandFollowerWD/1.0.3 +http://pcdev.pt/");

The 'User-Agent' header must be modified with the appropriate property or method.
Was it helpful?

Solution

After searching furder more I've found the answer.... Instead of using request.Headers.Add("User-Agent", "MyAppId/1.0.3 +http://example.pt"); I've used request.UserAgent = "MyAppId/1.0.3 +http://example.pt";

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top