问题描述
我在谷歌API和asp.net C#的工作,我的目标是使用服务帐户访问谷歌的API。
I am working in google api with asp.net c#, My goal is access google api using service account.
我已经导入所有需要的DLL来创建访问管理功能(管理SDK)。
I have imported all needed dlls to create service account to access admin features(admin sdk).
但我找不到ServiceAccountCredential。
But i couldn't find ServiceAccountCredential.
我怎么能在我的项目实施的?
How can i implement this in my project?
推荐答案
<一个href=\"http://contrib.google-api-dotnet-client.google$c$c.com/hg/1.8.0-rc/documentation/classGoogle_1_1Apis_1_1Auth_1_1OAuth2_1_1ServiceAccountCredential.html\">ServiceAccountCredential是Google.Apis.Auth.OAuth2的一部分
ServiceAccountCredential is part of Google.Apis.Auth.OAuth2
使用的BigQuery简单的例子:
Simple example using BigQuery:
using System;
using Google.Apis.Auth.OAuth2;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Bigquery.v2;
using Google.Apis.Services;
//Install-Package Google.Apis.Bigquery.v2
namespace GoogleBigQueryServiceAccount
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("BigQuery API - Service Account");
Console.WriteLine("==========================");
String serviceAccountEmail = "539621478854-imkdv94bgujcom228h3ea33kmkoefhil@developer.gserviceaccount.com";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { BigqueryService.Scope.DevstorageReadOnly }
}.FromCertificate(certificate));
// Create the service.
var service = new BigqueryService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "BigQuery API Sample",
});
}
}
}
这篇关于在哪里可以找到ServiceAccountCredential的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!