簡體   English   中英

Google API和OAuth2

[英]Google API & OAuth2

遵循此處概述的Google代碼示例。

我已經在自己的測試項目中復制了他們的代碼示例(在Visual Studio Express 2013中使用MVC 4模板),由於出現以下錯誤,我無法運行該項目:

錯誤1由於'Google.Apis.Sample.MVC4.Controllers.HomeController.IndexAsync(System.Threading.CancellationToken)'是返回'Task'的異步方法,因此return關鍵字后不能跟隨對象表達式。 您是否打算返回“任務”? 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'的異步方法,因此return關鍵字后不能包含對象表達式。 您是否打算返回“任務”? 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);
            }
        }
    }
}
 public async Task<ActionResult> IndexAsync(CancellationToken cancellationToken)

為我工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM