我正在尝试在需要编辑功能的网页中使用公共Google日历。 为此,我创建了日历并将其公开。然后我创建了一个Google服务帐户和相关的客户端ID。 我也启用了日历API,并将v3 dll添加到项目中。 我下载了p12证书,这就是问题出现的时间。Google日历API和共享主机问题
对Google的调用需要X509证书,但.NET框架的构建方式是使用用户临时文件夹。 由于它是Web服务器(GoDaddy)的共享主机,因此我无法修改应用程序池标识。 其结果是,我得到这个错误:
System.Security.Cryptography.CryptographicException: The system cannot find the file specified.
打电话时:
X509Certificate2 certificate = new X509Certificate2(GoogleOAuth2CertificatePath,
"notasecret", X509KeyStorageFlags.Exportable);
即cerificate VAR然后在谷歌通话使用:
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(GoogleOAuth2EmailAddress)
{
User = GoogleAccount,
Scopes = new[] { CalendarService.Scope.Calendar }
}.FromCertificate(certificate));
。 ..但我从来没有那么远。
问:有没有办法以不同的方式进行调用,即不使用X509证书,而使用JSON? 或者我可以让x509函数使用一般临时位置而不是我无法访问的用户位置,因为我无法更改应用程序池中的身份?
由于我完全卡住了,任何帮助,将不胜感激。
肯定使用JSON,你会遇到同样的问题 - 问题是“我无法加载文件”,而不是Google或X509特定的问题。您可以将证书嵌入到程序集中并使用'Assembly.GetManifestResourceStream'来加载数据... –
同意你在哪里放置GoogleOAuth2CertificatePath? – DaImTo
.p12文件位于App_Data/MyGoogleStorage文件夹中。 – Nick