I have a C# .net web application that I use to upload videos to Youtube. This worked about 6 months ago but now it has stopped working. The following code just hangs when I launch my website via Visual Studio on my local computer:
UserCredential credential;
using (var auth_stream = new FileStream(Server.MapPath("~/YouTube/client_secrets.json"), FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(auth_stream).Secrets,
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
I have also tried the following after looking at other posts on stack overflow:
UserCredential credentialS;
using (var auth_stream = new FileStream(Server.MapPath("~/YouTube/client_secrets.json"), FileMode.Open, FileAccess.Read))
{
credentialS = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "blahblah-myDetailsBlahBLah.apps.googleusercontent.com",
ClientSecret = "myClientSecret",
},
// This OAuth 2.0 access scope allows an application to upload files to the
// authenticated user's YouTube channel, but doesn't allow other types of access.
new[] { YouTubeService.Scope.YoutubeUpload },
"user",
CancellationToken.None
);
}
I also notived that I was using version 1.7.0-beta of the Google APIs so I upgraded via PackageManager console to version 1.8.2.
I also generated a new Client Secret via the Google Developer Console and used that in my website.
But after trying these steps the call to GoogleWebAuthorizationBroker.AuthorizeAsync still hangs. I notice that my website in my local browser refreshes as if its attempting to connect but the call is never seccessful.
How can I solve this??
I also ran into this issue using the Google Calendar API.
My application is scraping notices from various online resources and posting them to a shared google calendar.
It works fine in a development environment but didn't when I deployed it to a VM where it is running as a windows scheduled task every 15 minutes using a service account in that VM.
I remember that when first setting it up I had to go through the authorization step in the browser but it wasn't being triggered when run as a scheduled task.
I could not find a way to get it to prompt through the browser to grant access again.
As the service account C:\Users\\Documents.credentials\calendar-dotnet-quickstart folder was being created just fine, I simply copied the Google.Apis.Auth.OAuth2.Responses.TokenResponse-user from the same folder in my dev environment and it now works fine.
That may not be the best or ultimate solution to this but it works.
I suspect if I logged in as that service user for the scheduled task and ran from the command prompt I would get prompted via the browser to grant the authorization.
Hope this helps someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With