OAuth for installed applications with .NET
I am trying to get OAuth for installed applications to work with my code, with actually little success...
Here is the code:
GOAuthRequestFactory factory = new GOAuthRequestFactory("cl", "MyApp");
factory.ConsumerKey = "anonymous";
factory.ConsumerSecret = "anonymous";
// example of performing a query (use OAuthUri or query.OAuthRequestorId)
Uri calendarUri = new OAuthUri("http://www.google.com/calendar/feeds/default/owncalendars/full", "firstname.lastname", "gmail.com");
CalendarQuery query = new CalendarQuery();
query.Uri = calendarUri;
factory.AccountType = "GOOGLE";
factory.MethodOverride = true;
Console.WriteLine("Setting up proxy");
IWebProxy iProxy = WebRequest.DefaultWebProxy;
WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));
// potentially, setup credentials on the proxy here
myProxy.Credentials = Crede开发者_开发知识库ntialCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
factory.Proxy = myProxy;
CalendarService service = new CalendarService("MyApp");
service.RequestFactory = factory;
service.Query(query);
At the last line, I get an exception:
{"Execution of request failed: http://www.google.com/calendar/feeds/default/owncalendars/full?xoauth_requestor_id=firstname.lastname@gmail.com"}
The server returns:
Token invalid - Invalid AuthSub token.
Anyone with an idea?
I am actually not quite bound to OAuth, but ClientLogin seized working today in the morning for some reason... And anyway, I feel better when the users do not have to provide my application with their credentials.
Best would be a - working - example, no matter how simple :)
I've read somewhere on the net that .NET with OAuth does not work well with GData 1.4.0.2 (current version), and that it is working much better with the - experimental - 1.5.0.0, but was not able to find a locatino to download the experimental version :(
Thanks in advance!
精彩评论