【发布时间】:2018-11-12 04:59:14
【问题描述】:
我正在尝试让 google firebase 动态链接在我的 .net 核心项目上工作,我的代码如下
public static async Task<string> GetShortLink(string longLink)
{
var service = AuthenticateServiceAccount("gayan@empite.com", "Opt/Keys/quallogi-keys.json", new[] { "https://www.googleapis.com/auth/firebase" });
var request = service.ManagedShortLinks.Create(new CreateManagedShortLinkRequest
{
DynamicLinkInfo = new DynamicLinkInfo
{
//DynamicLinkDomain = "https://quallogi.page.link",
DomainUriPrefix = "quallogi.page.link",
AnalyticsInfo = new AnalyticsInfo(),
IosInfo = new IosInfo(),
Link = "https://github.com/distriqt/ANE-Firebase/wiki/DynamicLinks---Create-Dynamic-Links",
},
Suffix = new Suffix { Option = "SHORT" },
Name = "shortlink",
});
var response = await request.ExecuteAsync();
return response.PreviewLink;
}
public static FirebaseDynamicLinksService AuthenticateServiceAccount(string serviceAccountEmail, string serviceAccountCredentialFilePath, string[] scopes)
{
try
{
if (string.IsNullOrEmpty(serviceAccountCredentialFilePath))
throw new Exception("Path to the service account credentials file is required.");
if (!File.Exists(serviceAccountCredentialFilePath))
throw new Exception("The service account credentials file does not exist at: " + serviceAccountCredentialFilePath);
if (string.IsNullOrEmpty(serviceAccountEmail))
throw new Exception("ServiceAccountEmail is required.");
if (Path.GetExtension(serviceAccountCredentialFilePath).ToLower() == ".json")
{
GoogleCredential credential;
using (var stream = new FileStream(serviceAccountCredentialFilePath, FileMode.Open, FileAccess.Read))
{
credential = GoogleCredential.FromStream(stream)
.CreateScoped(scopes);
}
return new FirebaseDynamicLinksService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Firebasedynamiclinks Service account Authentication Sample",
});
}
else if (Path.GetExtension(serviceAccountCredentialFilePath).ToLower() == ".p12")
{
var certificate = new X509Certificate2(serviceAccountCredentialFilePath, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = scopes
}.FromCertificate(certificate));
return new FirebaseDynamicLinksService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Firebasedynamiclinks Authentication Sample",
});
}
else
{
throw new Exception("Unsupported Service accounts credentials.");
}
}
catch (Exception ex)
{
throw new Exception("CreateServiceAccountFirebasedynamiclinksFailed", ex);
}
}
但是当我运行代码时,谷歌会抛出异常
Google.Apis.Requests.RequestError 遇到内部错误。 [500] 错误 [ 消息 [遇到内部错误。] 位置 [ - ] 原因[backendError] 域[全局] ]
出了什么问题?
【问题讨论】:
标签: c# firebase .net-core firebase-dynamic-links