非常感谢Sam Leach
以下是我工作的app.config文件的示例:
<configuration>
...
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.5.19.0" newVersion="2.5.19.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="B03F5F7F11D50A3A" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-2.1.10.0" newVersion="2.1.10.0"/>
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
Run Code Online (Sandbox Code Playgroud)
我也发现了这个来源
编辑:原来的问题是在线下.
我正在使用.NET 4.0 Framework,从我的研究中我知道不再需要System.Threading.Tasks程序集(因为它是自动包含的).我错了吗?
如果我是对的,我现在非常确定会引发错误,因为google-api-dotnet-client开发人员使用的System.Threading.Tasks版本与Visual Studio 2010使用的版本不同.
我注意到当我删除一些行时检查我的应用程序的行为.
这些线出来了:
gcal = new CalendarService(new BaseClientService.Initializer()
{
Authenticator = auth,
ApplicationName = APP_NAME,
});
Run Code Online (Sandbox Code Playgroud)
所以,我的新问题是:
有没有办法强制在VS2010中使用一个特定版本的参考组件?
感谢您帮助我,我相信它会帮助很多人,因为google-calendar-api-v3的记录很糟糕.
亲切的问候,布鲁诺.
我的问题是我无法通过VisualStudio访问Google API作为服务.
我收到此错误:
L'exception System.IO.FileLoadException n'a pas été gérée
Message=Impossible de charger …Run Code Online (Sandbox Code Playgroud) c# google-calendar-api visual-studio-2010 jwt google-api-dotnet-client
好吧,我可以在Youtube上传视频,但我找不到从Youtube上删除视频/视频的方法或相关代码.
这是我试图删除youtube视频的代码.
private async Task Run()
{
UserCredential credential;
using (var stream = new FileStream("client_secret.json", FileMode.Open, FileAccess.Read))
{
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { YouTubeService.Scope.Youtube },
"user",
CancellationToken.None
);
}
var youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = Assembly.GetExecutingAssembly().GetName().Name
});
var videosDeleteRequest = youtubeService.Videos.Delete("Video ID");
await videosDeleteRequest.ExecuteAsync();
}
Run Code Online (Sandbox Code Playgroud)
但获得403回复
Error: Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermis
sions] Domain[global]
]
Run Code Online (Sandbox Code Playgroud)
一点帮助或任何可能的解决方案将是非常值得注意的.
google-api youtube-api c#-4.0 google-oauth google-api-dotnet-client
我一直在使用Google API Client Library for .NET将Google Analytics数据加载到我的应用程序中:
最近虽然我发现它已经开始完全冻结.该Execute()命令与Google服务器建立连接.
它成功地要求:
https://accounts.google.com/o/oauth2/token
Run Code Online (Sandbox Code Playgroud)
返回类似于:
{
"access_token" : "ya30.HAKlQSGZo2GnK5wxlxx9TLTQUyD9Xkt7AZxuQnDY-KhJuCyrCtN_xHIP",
"token_type" : "Bearer",
"expires_in" : 3600
}
Run Code Online (Sandbox Code Playgroud)
但是从来没有从Execute电话中回来.
控制台应用程序中的相同代码立即返回,但在IIS中它当前永远不会返回.
在以前的版本中它工作得很好(我不确定它改变了哪个版本).
我已经Load User Profile设定为真.
可能是什么导致了这个?
var SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"C:\TEMP\GoogleAnalytics-privatekey.p12";
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
// Create credentials (not my real login here)
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("86987278011-ctegcus4og7kn6oigkrv8po5pf67bbgj@developer.gserviceaccount.com")
{
Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
}.FromCertificate(certificate));
// Create the service
var …Run Code Online (Sandbox Code Playgroud) asp.net-mvc oauth google-api google-analytics-api google-api-dotnet-client
刚开始使用Google Apis.在我的Google Cloud Platform帐户中,我为域范围委派创建了一个服务帐户.我为此服务帐户保存了json格式的私钥文件.
在我的测试应用程序中,我正在创建一个GoogleCredential实例:
var credential =
GoogleCredential.FromStream(new FileStream("privatekey.json", FileMode.Open, FileAccess.Read))
.CreateScoped(Scopes);
Run Code Online (Sandbox Code Playgroud)
如何设置我想要冒充的用户?使用p12私钥时,我可以执行以下操作:
var credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer("xxx@developer.gserviceaccount.com") //service Account id
{
Scopes = Scopes,
User = "admin@xxx.com" //the user to be impersonated
}.FromCertificate(new X509Certificate2(@"xxx.p12", "notasecret", X509KeyStorageFlags.Exportable)));
Run Code Online (Sandbox Code Playgroud)
但是,我如何使用GoogleCredential和json privatkey文件"轻松实现"?
亲切的问候
我目前正在尝试通过C#与Google Admin SDK集成,以便我们可以通过自己的系统管理用户。但是,在运行项目时出现错误:未经授权的客户端。
我已经通过超级管理员帐户完成的操作:
这是我正在使用的代码。
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(_googleServiceSettings.Client_Email)
{
ProjectId = _googleServiceSettings.Project_Id,
User = "superadmin@google.com",
Scopes = new[] { DirectoryService.Scope.AdminDirectoryUser }
}.FromPrivateKey(_googleServiceSettings.Private_Key));
var service = new DirectoryService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "Test API"
});
var request = service.Users.Get("user@google.com");
var result = await request.ExecuteAsync();
Run Code Online (Sandbox Code Playgroud)
我得到的全部错误是
执行请求时发生未处理的异常。Google.Apis.Auth.OAuth2.Responses.TokenResponseException:错误:“ unauthorized_client”,说明:“客户端未经授权使用此方法检索访问令牌,或者客户端未获得所请求的任何范围的授权。”,Uri:“”
c# google-api google-api-dotnet-client google-admin-sdk gsuite
我们正在使用Google Analytics API v3 (点网版)在我们的网站上报告一些统计数据.我的代码在我的本地计算机上正常运行,但由于某些防火墙规则,它无法在生产服务器上运行.我们的系统管理员建议尝试使用代理.我在互联网上搜索了为Google AnalyticsAPI服务设置代理的任何指南,但没有运气.感谢这方面的任何指示.
编辑:
public DataTable GetSearchTrends()
{
string GoogleAnalyticsProfileId = AppConfigManager.GetGoogleAnalyticsProfileIdForInis();
var service = new AnalyticsService(new BaseClientService.Initializer()
{
Authenticator = Authenticate()
});
DataResource.GaResource.GetRequest request = service.Data.Ga.Get(
GoogleAnalyticsProfileId,
string.Format("{0:yyyy-MM-dd}", StartDate),
string.Format("{0:yyyy-MM-dd}", EndDate),
GoogleAnalyticsSearchUniquesMetric
);
request.Dimensions = GoogleAnalyticsSearchKeywordMetric;
request.Sort = string.Concat("-", GoogleAnalyticsSearchUniquesMetric);
request.MaxResults = NumberOfSearchTrendsToFetch;
GaData response = request.Fetch();
return SearchTrendsHelper.ConvertToDataTable(
response.Rows,
SearchTrendsKeywordsExcludeList,
NumberOfSearchTrendsToDisplay
);
}
private IAuthenticator Authenticate()
{
string GoogleAnalyticsServiceScope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();
string GoogleApiServiceAccountId = AppConfigManager.GetGoogleApiServiceAccountId();
string GoogleApiServiceAccountKeyFile = AppConfigManager.GetGoogleApiServiceAccountKeyFile();
string GoogleApiServiceAccountKeyPassword = AppConfigManager.GetGoogleApiServiceAccountKeyPassword();
AuthorizationServerDescription …Run Code Online (Sandbox Code Playgroud) .net google-api google-analytics-api google-api-dotnet-client
我在尝试运行我的c#控制台应用程序时收到此错误...我正在尝试调用google calender api v3来获取日历并将事件添加到日历中.根据google-api-dotnet-client的示例代码,我这样做.(https://code.google.com/p/google-api-dotnet-client/source/browse/Calendar.VB.ConsoleApp/Program .vb?repo = samples)这是vb.net代码.我将它转换为c#代码后使用此示例.
这是我的代码:
class Program
{
static void Main(string[] args)
{
try
{
new Program().Run().Wait();
}
catch (AggregateException ex)
{
foreach (var e in ex.InnerExceptions)
{
Console.WriteLine("ERROR: " + e.Message);
}
}
}
private async Task Run()
{
UserCredential credential;
IList<string> scopes = new List<string>();
CalendarService service;
scopes.Add(CalendarService.Scope.Calendar);
using (var stream = new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read))
{
// problem occuring during executing this statement.
credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
scopes,
"user", CancellationToken.None, new …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置c#代码来管理我们的Google域名.
每当我调用service.Users.List()或DirectoryService api中的任何其他方法时,我都会收到此错误.
Google.Apis.Requests.RequestError
Insufficient Permission [403]
Errors [
Message[Insufficient Permission] Location[ - ] Reason[insufficientPermissions] Domain[global]
]
Run Code Online (Sandbox Code Playgroud)
我按照OAuth设置上的所有说明进行操作.我使用的帐户是域管理员.
当我使用GAM.exe执行相同的操作时,我使用的客户端密码文件工作正常.这让我相信我在代码中做错了.
下面是我查询用户的代码,有什么我遗漏的吗?
static void Main(string[] args)
{
var applicationName = "App Project Name";
var userName = "admin@domain.com";
var clientID = "clientIDfromAPIcredentialpageonconsole.developers.google.com";
UserCredential credential;
using (var stream = new FileStream("C:\\gam\\client_secrets.json", FileMode.Open, FileAccess.Read))
{
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
new[] { DirectoryService.Scope.AdminDirectoryOrgunit, DirectoryService.Scope.AdminDirectoryUser },
userName,
CancellationToken.None, null).Result;
}
var service = new DirectoryService(new BaseClientService.Initializer()
{
ApplicationName = applicationName,
HttpClientInitializer = credential
});
var list = …Run Code Online (Sandbox Code Playgroud) Google 最近开始为我们提供服务帐户的 Json 密钥文件,而不是 P12 密钥文件。我一直在努力解决这个问题,那里没有很多信息,我所看到的信息表明这应该有效。
string[] scopes = new string[] { DriveService.Scope.Drive};
Stream stream = new FileStream(jsonKeyFilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
var credential = GoogleCredential.FromStream(stream).CreateScoped(scopes);
Run Code Online (Sandbox Code Playgroud)
但是它抛出以下异常
从 JSON 创建凭据时出错。无法识别的凭据类型。
我已经仔细检查了 json 密钥文件,下载了两个不同的文件,试图让它不起作用。
c# google-api google-oauth google-api-dotnet-client service-accounts
我有一个代码,其目的是重命名特定工作表,但是当执行 BatchUpdate 并且代码被破坏时,有人有任何想法吗?
public void UpdateSheetName(string sheetName,string newSheetName)
{
//get sheet id by sheet name
Spreadsheet spr = service.Spreadsheets.Get(SpreadsheetId).Execute();
Sheet sh = spr.Sheets.Where(s => s.Properties.Title == sheetName).FirstOrDefault();
int sheetId = (int)sh.Properties.SheetId;
BatchUpdateSpreadsheetRequest bussr = new BatchUpdateSpreadsheetRequest();
var request = new Request()
{
UpdateSpreadsheetProperties= new UpdateSpreadsheetPropertiesRequest(){
Properties=new SpreadsheetProperties()
{
Title= newSheetName,
},
Fields ="title"
}
};
bussr.Requests = new List<Request>();
bussr.Requests.Add(request);
var bur = service.Spreadsheets.BatchUpdate(bussr, SpreadsheetId);
bur.Execute();
}
Run Code Online (Sandbox Code Playgroud)
错误消息:“requests[0]”(oneof)的值无效,oneof 字段“kind”已设置。无法设置“updateSpreadsheetProperties”[400]
c# ×6
google-api ×6
.net ×3
google-oauth ×2
asp.net-mvc ×1
c#-4.0 ×1
gsuite ×1
jwt ×1
oauth ×1
oauth-2.0 ×1
youtube-api ×1