abujehad139 / google-api-dotnet-client

Automatically exported from code.google.com/p/google-api-dotnet-client
Apache License 2.0
0 stars 0 forks source link

Attempting to connect to Calendar/Event Service 401 Invalid Credentials error #263

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I am using the latest version of the API (1.2.4647.29713) and am unable to 
access any of the information due to an error 

Google.GoogleApiRequestException was unhandled
  HResult=-2146233088
  Message=Google.Apis.Requests.RequestError
Invalid Credentials [401]
Errors [
    Message[Invalid Credentials] Location[Authorization - header] Reason[authError] Domain[global]
]

  Source=Google.Apis
  StackTrace:
       at Google.Apis.Requests.Request.AsyncRequestResult.GetResponse() in z:\google-api\google-api-dotnet-client\9-21-2012\default\Src\GoogleApis\Apis\Requests\Request.cs:line 305
       at Google.Apis.Requests.ServiceRequest`1.GetResponse() in z:\google-api\google-api-dotnet-client\9-21-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 191
       at Google.Apis.Requests.ServiceRequest`1.Fetch() in z:\google-api\google-api-dotnet-client\9-21-2012\default\Src\GoogleApis\Apis\Requests\ServiceRequest.cs:line 211
       at LearnStyle.STMS.TaskManager.Tasks.CalendarService.Update() in c:\Projects\LearnStyle STMS\LearnStyle.STMS.TaskManager\Tasks\CalendarService.cs:line 44
       at LearnStyle.STMS.TaskManager.Program.Main(String[] args) in c:\Projects\LearnStyle STMS\LearnStyle.STMS.TaskManager\Program.cs:line 12
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.Net.WebException
       HResult=-2146233079
       Message=The remote server returned an error: (401) Unauthorized.
       Source=System
       StackTrace:
            at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
            at Google.Apis.Requests.Request.InternalEndExecuteRequest(IAsyncResult asyncResult) in z:\google-api\google-api-dotnet-client\9-21-2012\default\Src\GoogleApis\Apis\Requests\Request.cs:line 328
       InnerException: 

This is occurring for codesample,

 var auth = new OAuth2LeggedAuthenticator(Constants.ClientId, Constants.ClientSecret, user.Replace(string.Format("@{0}", Constants.ClientDomain), ""), Constants.ClientDomain);

                var service = new Google.Apis.Calendar.v3.CalendarService(auth);
                var bookings = service.CalendarList.List().Fetch().Items.Where(p => p.Summary == Constants.CalendarName).FirstOrDefault();

This code DID work as of version (1.1.4344.232403) which i was going to attempt 
to go ahead and use, but am now getting an error code of 400 when attempting to 
submit an event.

Is there a fix pending for this issue, or perhaps a recommended alternate 
method of Authentication to use?

Original issue reported on code.google.com by Anthony....@gmail.com on 1 Oct 2012 at 9:27

GoogleCodeExporter commented 9 years ago
I belive there has been some changes to authentication at the server end. I 
would try following the code in the samples, either for asp.net 
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.ASP.NET.Si
mpleOAuth2/Default.aspx.cs?repo=samples#72

Or for a native application: 
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.CreateTask
s/Program.cs?repo=samples#47

Hope that helps.

Original comment by davidwat...@google.com on 5 Oct 2012 at 2:34

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Same issue for me, using version 1.2.4737.

It worked with version 1.1.4344. :

var auth = new OAuth2LeggedAuthenticator("ConsumerKey", "ConsumerSecret", 
"UserLogin", "Domain"); // userLogin does not contain '@domain'

var _service = new CalendarService(auth);
_service.Key = this.APIKey;  // created in API Console 

CalendarListResource.ListRequest request = _service.CalendarList.List();
CalendarList feed = request.Fetch();

throws:

Google.Apis.Requests.RequestError
Invalid Credentials [401]
Errors [
    Message[Invalid Credentials] Location[Authorization - header] Reason[authError] Domain[global]
]

Original comment by madike...@gmail.com on 15 Jan 2013 at 8:45