Goodreads Developers discussion

29 views
questions > Not able to consume api

Comments Showing 1-2 of 2 (2 new)    post a comment »
dateUp arrow    newest »

message 1: by Vijay (new)

Vijay Parasi | 1 comments I am able to get access_token and also request_token.

var baseUrl = "http://www.goodreads.com";
var client = new RestClient(baseUrl);

client.Authenticator = OAuth1Authenticator.ForAccessToken("consumerKey", "consumerSecret", HttpContext.Current.Session["oauth_token"].ToString(), HttpContext.Current.Session["oauth_token_secret"].ToString());
var request = new RestRequest("oauth/access_token", Method.GET);
var response = client.Execute(request);

var qs = HttpUtility.ParseQueryString(response.Content);

if (qs != null && qs.Count > 0)
{
HttpContext.Current.Session["oauth_token"] = qs["oauth_token"];
HttpContext.Current.Session["oauth_token_secret"] = qs["oauth_token_secret"];
}

string goodreadsURL = "https://www.goodreads.com/oauth/autho..." + OAuthToken + "&oauth_callback=http://localhost:51650/GoodReadsResul...
Response.Redirect(goodreadsURL);

Overwriting access_token on session variables

client.Authenticator = OAuth1Authenticator.ForAccessToken("consumerKey", "consumer secret", HttpContext.Current.Session["oauth_token"].ToString(), HttpContext.Current.Session["oauth_token_secret"].ToString());
var request = new RestRequest("oauth/access_token", Method.GET);
var response = client.Execute(request);

var qs = HttpUtility.ParseQueryString(response.Content);

if (qs != null && qs.Count > 0)
{
HttpContext.Current.Session["oauth_token"] = qs["oauth_token"];
HttpContext.Current.Session["oauth_token_secret"] = qs["oauth_token_secret"];
}


After this if I try to call api methods as below it throws not authorized

var client2 = new RestClient(baseUrl);
client2.Authenticator = OAuth1Authenticator.ForProtectedResource("consumer key", "consumer secret", HttpContext.Current.Session["oauth_token"].ToString(), HttpContext.Current.Session["oauth_token_secret"].ToString());

var request2 = new RestRequest("notifications.xml", Method.GET);
var response2 = client.Execute(request2);

With the above code the response2 says not authorized. Can somebody please help me?


message 2: by Michael (new)

Michael Economy (michaeleconomy) What language is that?


Looks like you're not using an oauth library, I'd recommend looking for one in your language of choice.


back to top