0

我正在尝试使用 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>
4

1 回答 1

0

简短回答: 将解决方案中所有项目中所有引用的 Google.Apis 'DLL 文件更新为相同的版本。

长答案: 我的问题是我的解决方案中有两个项目,一个包含 Google.Apis v.1.4.0,另一个包含 Google.Apis v.1.5.0。因为使用 Google.Apis v.1.4.0 的那个是通过 REST API 为另一个项目提供服务的,所以在编译时没有发现错误。通过将两者都更新到最新版本,错误得到了解决。

于 2013-09-09T08:18:31.167 回答