按照here概述的Google代码示例。
我已经在我自己的测试项目中复制了他们的代码示例(在Visual Studio Express 2013中使用MVC 4模板),我无法运行该项目,因为我收到了这些错误:
错误1因为' Google.Apis.Sample.MVC4.Controllers.HomeController.IndexAsync(System.Threading.CancellationToken)'是一个返回' Task'的异步方法,返回关键字后面不能跟一个对象表达式。你打算回归'任务'? f:\ users \ sausages \ documents \ visual studio 2013 \ Projects \ GooglePOC \ GooglePOC \ Controllers \ googleAnalytics.cs 33 17 GooglePOC
错误2因为' Google.Apis.Sample.MVC4.Controllers.HomeController.IndexAsync(System.Threading.CancellationToken)'是一个返回' Task'的异步方法,返回关键字后面不能跟一个对象表达式。你打算回归'任务'? f:\ users \ sausages \ documents \ visual studio 2013 \ Projects \ GooglePOC \ GooglePOC \ Controllers \ googleAnalytics.cs 37 17 GooglePOC
这是它所抱怨的代码块:
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Mvc;
using Google.Apis.Auth.OAuth2.Mvc;
using Google.Apis.Drive.v2;
using Google.Apis.Services;
using Google.Apis.Sample.MVC4;
namespace Google.Apis.Sample.MVC4.Controllers
{
public class HomeController : Controller
{
public async Task IndexAsync(CancellationToken cancellationToken)
{
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var service = new DriveService(new BaseClientService.Initializer
{
HttpClientInitializer = result.Credential,
ApplicationName = "ASP.NET MVC Sample"
});
// YOUR CODE SHOULD BE HERE..
// SAMPLE CODE:
var list = await service.Files.List().ExecuteAsync();
ViewBag.Message = "FILE COUNT IS: " + list.Items.Count();
return View();
}
else
{
return new RedirectResult(result.RedirectUri);
}
}
}
}
答案 0 :(得分:2)
public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)
为我工作