我正在尝试使用 Google Shortener URL API https://developers.google.com/url-shortener/v1/getting_started但在使用 C# 库 Google.Apis.Urlshortener.v1 时遇到了一个严重问题。我正在尝试在 URL 上调用“插入”,以便使用 OAUTH2.0 身份验证获取缩短的 url。我已成功检索到有效的刷新令牌和身份验证器,但执行该函数时似乎缺少某些内容。我希望有人做过这项工作。
代码:
var init = new BaseClientService.Initializer();
init.Authenticator = _authenticator;
//init.ApiKey = ApiKey;
var urlService = new UrlshortenerService(init);
var shortUrl = urlService.Url.Insert(new Url { LongUrl = url }).Execute().Id; // fails...
堆栈跟踪:
<Error>
<Message>An error has occurred.</Message>
<ExceptionMessage>
Method 'get_ServiceParameters' in type 'Google.Apis.Urlshortener.v1.UrlshortenerService' from assembly 'Google.Apis.Urlshortener.v1, Version=1.5.0.18, Culture=neutral, PublicKeyToken=null' does not have an implementation.
</ExceptionMessage>
<ExceptionType>System.TypeLoadException</ExceptionType>
<StackTrace>
at DoguApi.Controllers.UrlShortenerController.GetShortenedUrl(String url) at lambda_method(Closure , Object , Object[] ) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass13.<GetExecutor>b__c(Object instance, Object[] methodParameters) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.Execute(Object instance, Object[] arguments) at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.<>c__DisplayClass5.<ExecuteAsync>b__4() at System.Threading.Tasks.TaskHelpers.RunSynchronously[TResult](Func`1 func, CancellationToken cancellationToken)
</StackTrace>
</Error>