0
我正在使用Umbraco 7.4.3的項目(ASP.NET MVC 5)。我正在嘗試與oauth2一起實施谷歌分析API。我使用了谷歌文檔平臺上提供的示例代碼。授權我的谷歌帳戶後,我得到一個正確的刷新令牌。但問題是這個刷新標記在URL中返回,並沒有通過我的控制器傳遞給我的視圖,它仍然是空的。我有一種感覺,即在用戶授權他或她的Google帳戶後,我的控制器不會等待執行它的代碼,因此控制器不會爲等待操作員所困擾。Umbraco異步SurfaceController
public class GoogleAnalyticsController : SurfaceController
{
public async Task<ActionResult> Add(CancellationToken cancellationToken)
{
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var service = new AnalyticsService(new BaseClientService.Initializer
{
HttpClientInitializer = result.Credential,
ApplicationName = "Analytics Dashboard"
});
// YOUR CODE SHOULD BE HERE..
ViewBag.AccessToken = result.Credential.Token.AccessToken;
ViewBag.RefreshToken = result.Credential.Token.RefreshToken;
var list = await service.Management.AccountSummaries.List().ExecuteAsync(cancellationToken);
ViewBag.Username = list.Username;
for (int i = 0; i < list.TotalResults; i++)
{
ViewBag.WebsiteNames += list.Items[i].Name + "(" + list.Items[i].WebProperties[0].WebsiteUrl + ")";
}
return View("~/Views/Configboard.cshtml");
}
else
{
return new RedirectResult(result.RedirectUri);
}
}
PS:我已經在ASP.NET MVC 5項目,而不一把umbraco安裝的完美的作品嚐試此示例代碼了。
任何一個能夠把我推向正確的方向嗎?
控制器操作的URL是什麼?當你在動作中放置一個斷點時,它會被擊中嗎? – elolos
/umbraco/surface/googleanalytics/add。當我放置一個斷點時,它確實被擊中,但結果始終爲空。 – user2963570
調試時,傳遞給操作的取消令牌是否具有您期望的值? – elolos