Archive for the ‘Code Commentary’ Category

Google API SDK OAuth2 Authentication “Invalid_Grant”

After hours of searching and not finding any information on the topic, I wanted to prevent a headache for the next guy who has to code against Google’s user directory API.

If you’ve had a solution working for a while, and all of a sudden your logs start to be filled with errors like this:

Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:”invalid_grant”, Description:””, Uri:””
at Google.Apis.Requests.ClientServiceRequest`1.Execute()

The solution is as simple as checking the time is synchronized to match what Google has. If your server has a time that is even 1 minute in the future off, Google will send an exception of “Invalid_Grant” due to a request claiming to come from the future.

*Edit*: Found info on Google here.

 

Upgrading Library from .Net 4.0 to .Net 4.5.2 – Regenerated Web Services Reference.cs

This quick tidbit is only for the few and far between, however, you may notice an issue when upgrading your projects to .Net 4.5.2. Your service references are all re-generated! Normally this is fine, except that I’ve noticed the code generator in VS2013 likes to name the namespaces the same as the root class. As an example, in your webservice named Foo:

1
2
3
4
5
6
7
8
/* This code was generated by a machine */
namespace Foo
{
     public class Foo
     {
          // Do stuff
     }
}

To deal with these issues, it is my belief that developers in C# should read the very informative article (part 1-4) here

Return top

INFORMATION

I do not adhere to a schedule. I post when I have something to say. I'm a programmer who in my spare time enjoys contemplating the meaning of life, the universe and, everything. So there will be code as well as random little stories, essays and, musing about whatever interests me at the moment.