几乎在过去24小时内,由于调用ResumeableUpload的UploadAsync,我一直在接收TaskCanceledExceptions.上传可能有90%的时间失败.我正在将视频上传到youtube.
我使用的是早期版本的google-apis(1.4),所以我尝试升级到1.5的最新nuget包,但问题没有改变.
知道可能会发生什么吗?我很困惑,因为我有时没有改变我的代码......
The stack trace is as follows:
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task)
at Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
at Microsoft.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
at Google.Apis.Upload.ResumableUpload`1.<Upload>d__0.MoveNext() in c:\code.google.com\google-api-dotnet-client\default_3\Tools\Google.Apis.Release\bin\Debug\output\default\Src\GoogleApis\Apis\[Media]\Upload\ResumableUpload.cs:line 362
Run Code Online (Sandbox Code Playgroud) 我尝试使用代表其他用户的服务帐户创建DriveService.
我已经从https://developers.google.com/drive/delegation中的 Google文档中复制了此代码
static DriveService BuildService() {
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
var provider = new AssertionFlowClient(GoogleAuthenticationServer.Description, certificate)
{
ServiceAccountId = SERVICE_ACCOUNT_EMAIL,
Scope = DriveService.Scopes.Drive.GetStringValue(),
};
var auth = new OAuth2Authenticator<AssertionFlowClient>(provider, AssertionFlowClient.GetState);
return new DriveService(auth);
}
Run Code Online (Sandbox Code Playgroud)
但是在尝试构建项目时我收到了这个警告:
警告4'Google.Apis.Authentication.OAuth2.DotNetOpenAuth.AssertionFlowClient'已过时:'不再支持AssertionFlowClient,它将在1.7.0-beta中删除.考虑使用新的Google.Apis.Auth NuGet包中的ServiceAccountCredential.
我也得到这个错误:
错误11参数1:无法从'Google.Apis.Authentication.OAuth2.OAuth2Authenticator'转换为'Google.Apis.Services.BaseClientService.Initializer'
然后我用Google搜索了ServiceAccountCredential并最终获得了此代码(来自此页面:https: //code.google.com/p/google-api-dotnet-client/wiki/OAuth2#Service_Accounts)
static DriveService BuildService() {
X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
{
User = "someone@mydomain.mygbiz.com",
Scopes = new[] { DriveService.Scope.DriveFile }
}.FromCertificate(certificate));
var service …Run Code Online (Sandbox Code Playgroud) 我正在尝试在Windows Azure云中部署ASP.NET应用程序.我正在为应用程序中的一个调用使用Google API.当我这样做时,我收到以下错误:
System.UnauthorizedAccessException:拒绝访问路径'Google.Apis.Auth'
ASP.NET无权访问所请求的资源.考虑将资源的访问权限授予ASP.NET请求标识.ASP.NET具有基本进程标识(IIS 5上通常为{MACHINE}\ASPNET,IIS 6和IIS 7上为网络服务,IIS 7.5上已配置的应用程序池标识),如果应用程序未模拟,则使用该标识.如果应用程序模拟通过,则标识将是匿名用户(通常为IUSR_MACHINENAME)或经过身份验证的请求用户.
要授予对文件的ASP.NET访问权限,请在"文件资源管理器"中右键单击该文件,选择"属性",然后选择"安全"选项卡.单击"添加"以添加适当的用户或组.突出显示ASP.NET帐户,并选中所需访问的框
我试过研究这个,但所有的建议都谈到了改变IIS服务器的设置,我不相信我有权访问,因为它在云中运行.有人可以帮忙吗?
编辑:这是给出错误的函数的代码:
Async Function SpecialTest() As Task(Of String)
Dim credential As UserCredential
Dim clientSecretsPath As String = Server.MapPath("~/App_Data/client_secret.json")
Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add(CalendarService.Scope.Calendar)
Dim stream As FileStream = New FileStream(clientSecretsPath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
Using stream
credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync(GoogleClientSecrets.Load(stream).Secrets, scopes, "user3", CancellationToken.None)
End Using
Dim baseInitializer = New BaseClientService.Initializer()
With baseInitializer
.HttpClientInitializer = credential
.ApplicationName = "P1"
End With
Dim service = New CalendarService(baseInitializer)
Dim Calendars …Run Code Online (Sandbox Code Playgroud) 我正在学习C#(开发用于Windows手机),并且我试图将我的用户验证到Google的帐户中.我正在使用此代码:https: //developers.google.com/api-client-library/dotnet/guide/aaa_oauth#wp
var credential = await GoogleWebAuthorizationBroker.AuthorizeAsync(
new FileStream("client_secrets.json", FileMode.Open, FileAccess.Read),
new[] { DriveService.Scope.Drive },
"user",
CancellationToken.None);
Run Code Online (Sandbox Code Playgroud)
但是,我不知道为什么,我不能使用'GoogleWebAuthorizationBroker'.我已经安装了所有引用,并且我使用了所有的导入.
当我运行我的程序时,我得到了这两条消息:
'当前上下文中不存在'CancellationToken'这个名字'
'当前上下文中不存在'GoogleWebAuthorizationBroker'这个名称'



更新:
为了最小化我的反馈周期,我从头开始创建一个新的Windows Phone项目,使用Windows Phone OS 7.1作为我的目标操作系统版本,然后我在包管理器控制台中执行这些命令:
pm> install-package google.apis -pre
pm> install-package google.apis.drive.v2 -pre
Run Code Online (Sandbox Code Playgroud)
然后,在我的MainPage.xaml.cs中,我写了这些导入:
using Google.Apis.Auth.OAuth2;
using Google.Apis.Services;
using System.IO;
using Google.Apis.Drive.v2;
using Google.Apis.Util.Store;
using System.Threading;
Run Code Online (Sandbox Code Playgroud)
最后,我试图通过IntelliSense简单地调用'GoogleWebAuthorizationBroker',但我找不到它.因此,作为我的上一次测试,我编写了"GoogleWebAuthorizationBroker"来查看Visual Studio是否指出了我的错误并提出了任何解决方案,但VS只给了我创建新类或新类型的选项.
最后但并非最不重要的是,我使用Visual Studio Express 2012 for Windows Phone,不知道它是否会影响...
UPDATE2:
当我在对象浏览器中扩展Google.Apis.Auth时,我找不到丢失的类(GoogleWebAuthorizationBroker),看起来我的安装进展不顺利......
更新3:
根据NuGet(https://www.nuget.org/packages/Google.Apis),Google.Apis与Windows Phone 7.5和8.0兼容.正如我在那里所说,我使用Windows Phone OS 7.1作为我的目标操作系统版本,我更新了我的7.1 SDK,但找不到7.5 sdk,所以,我应该使用7.8吗?请记住,我需要为Windows Phone 7.X开发
这更像是关于.Net Google Drive v2库中的一个错误的FYI.
使用时:
service.Files.Insert(body, Stream, mimeType)
确保Stream位置为0.否则您将收到错误:
System.InvalidOperationException: The given header was not found.
Run Code Online (Sandbox Code Playgroud)
在编写了一些比较流的代码之后,我在解决这个错误之前已经挣扎了2天.
我们有一个使用Gmail API来访问Gmail中电子邮件的应用程序。
我们随机收到以下错误消息
Google.Apis.Requests.RequestError超出速率限制[429]错误[消息[超出速率限制]位置[-]原因[rateLimitExceeded]域[usageLimits]]
然后我们在错误事件中重试代码并得到
Google.Apis.Requests.RequestError后端错误[500]错误[消息[后端错误]位置[-]原因[backendError]域[全局]]
然后我们在发生错误事件时在我们的代码中重试(我们尝试了3次),它按预期工作。
此处的Gmail API后端存在一些问题。我们每天要进行1000次以下的Gmail API调用,并且没有并行进行,因此我看不到我们违反了任何限制。
还有其他人遇到这种奇怪的行为吗?
这是被调用的代码
UsersResource.MessagesResource.GetRequest gr = gs.Users.Messages.Get(emailAccount, msgId);
{
gr.Format = UsersResource.MessagesResource.GetRequest.FormatEnum.Raw;
Message m = new Message();
try
{
m = gr.Execute();
}
}
Run Code Online (Sandbox Code Playgroud) 我们已从TFS 2010迁移到TeamCity,我们在构建解决方案文件时遇到了问题.
我们使用的是.NET 4.0.谷歌图书馆在尝试构建时会出现.NET 4.0 + system.net.http的问题.我们设法让这个设置在TFS(它使用MSBuild 4.0)上运行而没有错误.
App.config应该有正确的程序集:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.6.9.0" newVersion="2.6.9.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Net.Http.Primitives" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-2.2.28.0" newVersion="2.2.28.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
Run Code Online (Sandbox Code Playgroud)
我们已经尝试过: - 使用不同的跑步者类型:Visual Studio,MSbuild - 直接引用所有Dlls(google + system.net.http +等) - 在这些DLL上使用直接Nuget包恢复(它恢复一切正常) …
我正在尝试使用Owin在Google.Apis请求中提供的AccessToken,但我收到异常System.InvalidOperationException(附加信息:访问令牌已过期但我们无法刷新它).
我的Google身份验证配置正常,我可以使用它成功登录我的应用程序.我将context.AccessToken存储为身份验证回调中的声明(GoogleOAuth2AuthenticationProvider的OnAuthenticated"event").
我的Startup.Auth.cs配置(app.UseGoogleAuthentication(ConfigureGooglePlus()))
private GoogleOAuth2AuthenticationOptions ConfigureGooglePlus()
{
var goolePlusOptions = new GoogleOAuth2AuthenticationOptions()
{
ClientId = "Xxxxxxx.apps.googleusercontent.com",
ClientSecret = "YYYYYYzzzzzz",
Provider = new GoogleOAuth2AuthenticationProvider()
{
OnAuthenticated = context =>
{
context.Identity.AddClaim(new System.Security.Claims.Claim("Google_AccessToken", context.AccessToken));
return Task.FromResult(0);
}
},
SignInAsAuthenticationType = DefaultAuthenticationTypes.ExternalCookie
};
goolePlusOptions.Scope.Add("https://www.googleapis.com/auth/plus.login");
goolePlusOptions.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
return goolePlusOptions;
Run Code Online (Sandbox Code Playgroud)
}
抛出异常的代码(Execute()方法)
var externalIdentity = await AuthenticationManager.GetExternalIdentityAsync(DefaultAuthenticationTypes.ExternalCookie);
var accessTokenClaim = externalIdentity.FindAll(loginProvider + "_AccessToken").First();
var secrets = new ClientSecrets()
{
ClientId = "Xxxxxxx.apps.googleusercontent.com",
ClientSecret = "YYYYYYzzzzzz"
};
IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = …Run Code Online (Sandbox Code Playgroud) asp.net-mvc google-oauth google-api-dotnet-client owin google-plus-signin
错误:解析值时遇到意外字符:e。路径'',第0行,位置0。
我正在使用Google .Net客户端库来访问Google驱动器API v3,尤其是Google.Apis.Drive.v3程序包。我正在通过C#授权使用“服务帐户”。
使用p12密钥进行授权是没有问题的。但是,建议使用JSON,并保留p12格式以实现向后兼容。
我从Google Developers Console下载了JSON文件,并尝试使用以下代码进行授权:
public static Google.Apis.Drive.v3.DriveService AuthenticateServiceAccountJSON(string keyFilePath) {
// check the file exists
if (!File.Exists(keyFilePath)) {
Console.WriteLine("An Error occurred - Key file does not exist");
return null;
}
string[] scopes = new string[] { DriveService.Scope.Drive, // view and manage your files and documents
DriveService.Scope.DriveAppdata, // view and manage its own configuration data
DriveService.Scope.DriveFile, // view and manage files created by this app
DriveService.Scope.DriveMetadataReadonly, // view metadata for files
DriveService.Scope.DriveReadonly, // view files …Run Code Online (Sandbox Code Playgroud) c# google-api google-drive-api google-api-dotnet-client service-accounts
我知道,在使用OAuth授权请求时,我们可以使用多个范围来请求用户的特定权限。我想请求允许下载带有公共共享链接的文件(用户实际上将提供此链接)。
但是,此处列出的范围不提供此类选项。我不想获得所有文件的许可并吓scar他们。
下面是我正在使用的代码。有任何想法吗?您认为有可能获得具有公共链接的文件的许可吗?可以使用共享链接的访问权限吗?
private string[] Scopes = { DriveService.Scope.DriveFile};
private DriveService GetDriveServiceInstance()
{
UserCredential credential;
using (var stream = new FileStream("Services/credentials.json", FileMode.Open, FileAccess.Read))
{
string credPath = "token.json";
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets,
Scopes,
"user",
CancellationToken.None,
new FileDataStore(credPath, true)).Result;
Console.WriteLine("Credential file saved to: " + credPath);
}
BaseClientService.Initializer bcs = new BaseClientService.Initializer();
bcs.HttpClientInitializer = credential;
bcs.ApplicationName = "synergy";
DriveService service = new DriveService(bcs);
return service;
}
Run Code Online (Sandbox Code Playgroud) c# google-api google-drive-api google-oauth google-api-dotnet-client
c# ×4
google-api ×3
asp.net ×2
google-oauth ×2
asp.net-mvc ×1
azure ×1
gmail-api ×1
iis ×1
oauth-2.0 ×1
owin ×1
quota ×1
teamcity ×1
vb.net ×1