1024programmer Java GoogleOauth error: At least one client secret (installed or web) should be set

GoogleOauth error: At least one client secret (installed or web) should be set

I am using Google’s Oauth 2.0 to upload videos to Youtube through our server. My client ID is “Service Account”. I downloaded the json key and added it to my solution.

This is the relevant code:

 private async Task Run(string filePath)
             UserCredential credential;
             var keyUrl = System.Web.HttpContext.Current.Server.MapPath("~/content/oauth_key.json");
             using (var stream = new FileStream(keyUrl, FileMode.Open, FileAccess.Read))
                 credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
                     // 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 },

             var youtubeService = new YouTubeService(new BaseClientService.Initializer()
                 HttpClientInitializer = credential,
                 ApplicatiOnName= Assembly.GetExecutingAssembly().GetName().Name

When I run it, I get this error: At least one client secret (installed or web) should be set.

However, there is no “customer secret” in my json:

   "private_key_id": "9d98c06b3e730070806dcf8227578efd0ba9989b",
   "private_key": "-----BEGIN PRIVATE KEY-----\nMIICdQIBADANBgkqhk etc,
   "client_email": "546239405652-8igo05a5m8cutggehk3rk3hspjfm3t04@developer.gserviceaccount.com",
   "client_id": "546239405652-8igo05a5m8cutggehk3rk3hspjfm3t04.apps.googleusercontent.com",
   "type": "service_account"

So I think I’m overlooking something. Maybe I can’t use a “service account”? I don’t know…

1> Sergey Tihon..:

Solution using json file The solutions are very similar.

This is an example of a VisionService created using a GoogleCredential object created from a json file ServiceAccountCredential.

GoogleCredential credential;
 using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
     credential = GoogleCredential.FromStream(stream)

 var service = new VisionService(new BaseClientService.Initializer()
     HttpClientInitializer = credential,
     ApplicatiOnName= "my-app-name",

This example requires two NuGet packages:


The main focus here should be _GoogleCredential.FromStream_, followed by _CreateScoped_

2> Ash..:

I managed to get a service account to process P12 files, but would like to know how to use a JSON file, or just get the values ​​from a JSON file to create the certificate.

Get token

 private static String GetOAuthCredentialViaP12Key()
         const string serviceAccountEmail = SERVICE_ACCOUNT_EMAIL;
         var certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);

         var scope = DriveService.Scope.Drive + " https://spreadsheets.google.com/feeds";
         var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail)
                                                             Scopes = new[] { scope }
                                                        }.FromCertificate(certificate) );

         if (credential.RequestAccessTokenAsync(CancellationToken.None).Result == false)

             return null;

         return credential.Token.AccessToken;

This is how I use the token I got

 // Initialize the variables needed to make the request
         OAuth2Parameters parameters = new OAuth2Parameters {AccessToken = token};
         GOAuth2RequestFactory requestFactory = new GOAuth2RequestFactory(null, "MySpreadsheetIntegration-v1", parameters);
         SpreadsheetsService service = new SpreadsheetsService("MySpreadsheetIntegration-v1");
         service.RequestFactory = requestFactory;

This article is from the internet and does not represent1024programmerPosition, please indicate the source when reprinting:https://www.1024programmer.com/754402

author: admin

Previous article
Next article

Leave a Reply

Your email address will not be published. Required fields are marked *

Contact Us

Contact us


Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top