谷歌云C#API永不回调



我正在使用以下代码访问我的存储:

private static IConfigurableHttpClientInitializer GetInstalledApplicationCredentials()
{
string serviceAccountEmail = "xxxxxxxx";
X509Certificate2 certificate;
using (Stream stream = new FileStream(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "App_Data", "path.p12"), FileMode.Open, FileAccess.Read))
{
    using (MemoryStream ms = new MemoryStream())
    {
        stream.CopyTo(ms);
        certificate = new X509Certificate2(ms.ToArray(), "notasecret", X509KeyStorageFlags.Exportable);
    }
}
ServiceAccountCredential credential = new ServiceAccountCredential(
    new ServiceAccountCredential.Initializer(serviceAccountEmail)
    {
        Scopes = new[] {
            StorageService.Scope.DevstorageFullControl
    },
}.FromCertificate(certificate));
return credential;
}
        private static StorageService GetStoreageService()
    {
        var service = new StorageService(
            new BaseClientService.Initializer()
            {
                HttpClientInitializer = GetInstalledApplicationCredentials(),
                ApplicationName = "app"
            }
        );
        return service;
    }
public static byte[] DownloadAudio(string fileName)
    {
        var service = GetStoreageService();
        var req = service.Objects.Get(bucketName, fileName);
        var readobj = req.Execute();
        var downloader = new MediaDownloader(service);
        using (var ms = new MemoryStream())
        {
            downloader.Download(readobj.MediaLink, ms);
            return ms.ToArray();
        }
    }

在行var readobj=req中。执行();我的应用程序只是阻塞,从不给我响应。我已经尝试过使用JSON和OAuth。唯一的区别是,在IIS Express中使用OAuth可以工作,但在IIS Express之外则不然。使用P12或JSON,我在IIS或IIS Express中都有问题。

知道吗?

谢谢,Murilo

不确定这是否是问题所在,但请尝试

certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);

相关内容

  • 没有找到相关文章

最新更新