Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:17:57+00:00 2026-05-26T08:17:57+00:00

I am trying to get OAuth working with the .NET library for Google Data

  • 0

I am trying to get OAuth working with the .NET library for Google Data API. Unfortunately, whenever I call GetUnauthorizedRequestToken, I get a 400 Bad Response error. Here is my code…

OAuthParameters parameters = new OAuthParameters() {
    ConsumerKey = DOMAIN_NAME,
    ConsumerSecret = SECRET_KEY,
    Scope = "https://docs.google.com/feeds/",
    Callback = Request.RawUrl,
    SignatureMethod = "HMAC-SHA1"
};

OAuthUtil.GetUnauthorizedRequestToken(parameters);

As far as I know I am correctly following the instructions here:
http://code.google.com/apis/gdata/docs/auth/oauth.html

Any help with this problem would be much appreciated!

EDIT: 9/10/2011 11:56 PM PST

First of all, thank you so much for the comments!

So I’ve fiddled around a bit and got the Unauthorized Request Token working, but OAuth is still not really working… here is a more complete code dump :-\

string token = Request["oauth_token"];
if (!String.IsNullOrEmpty(token)) {
    OAuthParameters tParams = new OAuthParameters() {
        ConsumerKey = DOMAIN_NAME,
        ConsumerSecret = SECRET_KEY,
        Scope = S_SCOPE,
        Callback = S_CALLBACK,
        SignatureMethod = "HMAC-SHA1"
    };
    tParams.Verifier = Request["oauth_verifier"];
    tParams.Token = token;

    try {
        // http://code.google.com/apis/gdata/docs/auth/oauth.html

        // 1. Extract token from the callback URL
        //OAuthUtil.UpdateOAuthParametersFromCallback(Request.Url.Query, parameters);

        // 2. Upgrade to an access token
        OAuthUtil.GetAccessToken(tParams);
        string accessToken = tParams.Token;
        string accessTokenSecret = tParams.TokenSecret;

        Session["sp"] = tParams; // don't worry, we don't even get here yet
        return RedirectToAction("List");
    }
    catch (System.Net.WebException ex) {
        // print out tons of stuff (removed for sanity)
    }
    
    //... and start over again
}


try {
    OAuthParameters parameters = new OAuthParameters() {
        ConsumerKey = DOMAIN_NAME,
        ConsumerSecret = SECRET_KEY,
        Scope = S_SCOPE,
        Callback = S_CALLBACK,
        SignatureMethod = "HMAC-SHA1"
    };

    OAuthUtil.GetUnauthorizedRequestToken(parameters);
    string approvalPageUrl = OAuthUtil.CreateUserAuthorizationUrl(parameters);
    ViewBag.AuthUrl = approvalPageUrl;

}
catch (System.Net.WebException ex) {
    // print out more stuff
}

and this is the error I am seeing (slightly modified to remove sensitive data, however I left all the symbols as-is in case someone thinks this is an encoding error):

X-Content-Type-Options = nosniff
X-XSS-Protection = 1; mode=block
Content-Length = 386
Cache-Control = private, max-age=0
Content-Type = text/plain; charset=UTF-8
Date = Sun, 11 Sep 2011 06:53:26 GMT
Expires = Sun, 11 Sep 2011 06:53:26 GMT
Server = GSE

/accounts/OAuthGetAccessToken
signature_invalid
base_string:GET&https%3A%2F%2Fwww.google.com%2Faccounts%2FOAuthGetAccessToken&oauth_consumer_key%3Dmydomain.com%26oauth_nonce%3D4432dc4bd59b4ea0b133ea52cb450062%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1315724016%26oauth_token%3D4%252FGeEWOLvQL_eGlj8zAdrzi7YPhmhS%26oauth_verifier%3DMkGYPy8qeZPRg7gLKKXsYIiM%26oauth_version%3D1.0


Callback = http://mydomain.com/auth
ConsumerKey = mydomain.com
ConsumerSecret = RxGavGhuXi92sy3F-Q3DKcY_
Nonce = 4430dc4bd59b4ea3b133ea52cb450062
Scope = https://docs.google.com/feeds
SignatureMethod = HMAC-SHA1
Timestamp = 1315724016
Token = 4/GeAWOLvQL_eGlj1zEerzi7YPhmhS
TokenSecret = 
Verifier = MkXLPy8qeZARq7aLKXKsYIiM
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:17:58+00:00Added an answer on May 26, 2026 at 8:17 am

    I struggled through this and was able to put together my own MVC2 class to handle this whole process. Take a look and let me know if this helps you out.

    public class GoogleController : ApplicationController
    {
        //
        // GET: /Google/
    
        public ActionResult Index()
        {
            return View();
        }
    
        public ActionResult Authorize()
        {
            OAuthParameters parameters = BuildParameters();
    
            // build the token for unauthorized requests and generate the url
            GetUnauthorizedRequestToken(parameters);
            string authorizationUrl = OAuthUtil.CreateUserAuthorizationUrl(parameters);
    
            // store the parameters temporarily and redirect to google for authorization
            SaveParametersTokens(parameters);
            Response.Redirect(authorizationUrl);
            return View();
        }
    
        public ActionResult Oauth()
        {
            // retrieve and update the tokens for temporary authentication
            OAuthParameters parameters = BuildParameters();
            OAuthUtil.UpdateOAuthParametersFromCallback(Request.Url.Query, parameters);
    
            // finally, get the token we need b@#$!!!
            OAuthUtil.GetAccessToken(parameters);
    
            // save those tokens into the database
            SaveParametersTokens(parameters);
    
            // all the success in the world, return back
            return RedirectToAction("Index", "Admin");
        }
    
        public ActionResult DeleteParametersTokens()
        {
            var oldTokens = (from t in context.GO_GoogleAuthorizeTokens select t);
    
            // if there is a token, call google to remove it
            /*if (oldTokens.Count() > 0)
            {
                GO_GoogleAuthorizeToken tokens = oldTokens.First();
                AuthSubUtil.revokeToken(tokens.Token, null);
            }*/
    
            // delete the tokens from the database
            context.GO_GoogleAuthorizeTokens.DeleteAllOnSubmit(oldTokens);
            context.SubmitChanges();
    
            // redirect to the administrator homepage when the tokens are deleted
            return RedirectToAction("Index", "Admin");
        }
    
        #region private helper methods
    
        private void GetUnauthorizedRequestToken(OAuthParameters parameters)
        {
            String requestTokenUrl = "https://www.google.com/accounts/OAuthGetRequestToken";
            Uri requestUri = new Uri(string.Format("{0}?scope={1}", requestTokenUrl, OAuthBase.EncodingPerRFC3986(parameters.Scope)));
    
            // callback is only needed when getting the request token
            bool callbackExists = false;
            if (!string.IsNullOrEmpty(parameters.Callback))
            {
                parameters.BaseProperties.Add(OAuthBase.OAuthCallbackKey, parameters.Callback);
                callbackExists = true;
            }
    
            string headers = OAuthUtil.GenerateHeader(requestUri, "GET", parameters);
            System.Net.WebRequest request = System.Net.WebRequest.Create(requestUri);
            request.Headers.Add(headers);
    
            System.Net.WebResponse response = request.GetResponse();
            string result = "";
            if (response != null)
            {
                System.IO.Stream responseStream = response.GetResponseStream();
                System.IO.StreamReader reader = new System.IO.StreamReader(responseStream);
                result = reader.ReadToEnd();
            }
    
            if (callbackExists)
            {
                parameters.BaseProperties.Remove(OAuthBase.OAuthCallbackKey);
            }
    
            // split results and update parameters
            SortedDictionary<string, string> responseValues = OAuthBase.GetQueryParameters(result);
            parameters.Token = responseValues[OAuthBase.OAuthTokenKey];
            parameters.TokenSecret = responseValues[OAuthBase.OAuthTokenSecretKey];
        }
    
        private bool SaveParametersTokens(OAuthParameters parameters)
        {
            try
            {
                // first delete any old ones
                var oldTokens = (from t in context.GO_GoogleAuthorizeTokens select t);
                context.GO_GoogleAuthorizeTokens.DeleteAllOnSubmit(oldTokens);
                context.SubmitChanges();
    
                // now create a new one
                GO_GoogleAuthorizeToken newToken = new GO_GoogleAuthorizeToken
                {
                    Token = parameters.Token,
                    TokenSecret = parameters.TokenSecret
                };
                context.GO_GoogleAuthorizeTokens.InsertOnSubmit(newToken);
                context.SubmitChanges();
            }
            catch { return false; }
    
            return true;
        }
    
        private OAuthParameters BuildParameters()
        {
            // build the base parameters
            string scope = "https://www.google.com/calendar/feeds/ https://docs.google.com/feeds/ https://mail.google.com/mail/feed/atom/";
            string callback = String.Format("http://{0}/Google/Oauth", Request.Url.Authority);
            OAuthParameters parameters = new OAuthParameters
            {
                ConsumerKey = kConsumerKey,
                ConsumerSecret = kConsumerSecret,
                Scope = scope,
                Callback = callback,
                SignatureMethod = "HMAC-SHA1"
            };
    
            // check to see if we have saved tokens
            var tokens = (from a in context.GO_GoogleAuthorizeTokens select a);
            if (tokens.Count() > 0)
            {
                GO_GoogleAuthorizeToken token = tokens.First();
                parameters.Token = token.Token;
                parameters.TokenSecret = token.TokenSecret;
            }
    
            return parameters;
        }
    
        #endregion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get Oauth working with the Google API using Python. I
I'm trying to get Twitter authentication working on my ASP.NET site. When you create
Im trying to get TripIt OAuth authentication working, but I find the documentation to
i'm trying to get an OAuth server working but i'm kinda stuck a bit
I am trying to get gmail contacts using Google contacts api . For this
I'm currently working with the Google Picasa API trying to list albums. The code
Trying to get this example working from http://www.munna.shatkotha.com/blog/post/2008/10/26/Light-box-effect-with-WPF.aspx However, I can't seem to get
Trying to get my mind around google protobuf. I found some implementation of protobuf
I'm trying to get twitter update_profile_image to work using OAuth. I was using curl
I'm trying to create an event through the API and it is mostly working,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.