我正在關注Google .Net Quickstart。我已經正確地設置在控制檯的開發應用,並在MVC控制器已經得到這個(我相信)......GMail API未正確認證
public class HomeController : Controller
{
static string[] Scopes = { GmailService.Scope.GmailReadonly };
static string ApplicationName = "APP NAME";
public ActionResult Index()
{
ViewBag.Title = "Home Page";
Run();
return View();
}
private void Run()
{
UserCredential credential;
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = "<<MY REAL CLIENT ID IS HERE>>",
ClientSecret = "<<MY REAL CLIENT SECRET IS HERE>>"
},
Scopes,
"<<MY EMAIL ADDRESS>>",
CancellationToken.None, new FileDataStore("Mail.Labels")).Result;
}
}
我已設置項目最多每次在端口37623運行,我有在開發者控制檯上設置客戶端以允許重定向到http://localhost:37623/Home/Index
。
當我運行應用程序時,我是一個GMail帳戶列表(我有一對夫婦),即使我已明確指出要使用哪個帳戶。當我點擊帳戶選擇器選擇一個帳戶時,我立即顯示一個錯誤頁面,表示我已經返回400錯誤:redirect_uri_mismatch。
如果我看的錯誤頁面就說明這個請求的詳細內容...
access_type=offline
scope=https://www.googleapis.com/auth/gmail.readonly
response_type=code
redirect_uri=http://localhost:41509/authorize/
client_id=<<MY CLIENT ID>>
正如你所看到的,REDIRECT_URI 爲錯誤的;它指向端口41509(在這種情況下,它隨每次調用而變化)。
我缺少什麼?我應該做的是什麼,我不是?在撥打電話時,似乎沒有設置重定向URI GoogleWebAuthorizationBroker.AuthorizeAsync
我認爲這將是一個10分鐘的練習。 :-(