Jednak nie jestem w stanie sobie poradzić. Korzystając z kodu google'a jaki powyżej mi podesłałeś. Jeśli chodzi o zdobycie tokena dla danych to jest ok, ale np wykonanie Metody aby zdobyc liste kont nie udaje się a w odpowiedzi dostaję błąd 403 Insufficient Permission.
controller:
public class HomeController : Controller
{
public async Task<ActionResult> Index()
{
CancellationToken cancellationToken;
var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).AuthorizeAsync(cancellationToken);
if (result.Credential != null)
{
var gas = new AnalyticsService(new BaseClientService.Initializer()
{
HttpClientInitializer = result.Credential,
ApplicationName = "api_test",
});
ManagementResource.AccountsResource.ListRequest AccountListRequest = gas.Management.Accounts.List();
Accounts AccountList = AccountListRequest.Execute();
string a = gas.ApiKey;
return View();
}
else
{
return new RedirectResult(result.RedirectUri);
}
}
AppFlowMetadata:
private static readonly IAuthorizationCodeFlow flow =
new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer
{
ClientSecrets = new ClientSecrets
{
ClientId = "HASH.apps.googleusercontent.com",
ClientSecret = "HASH",
},
Scopes = new[] { DriveService.Scope.Drive },
DataStore = new FileDataStore("Drive.Api.Auth.Store")
});
public override string GetUserId(Controller controller)
{
// In this sample we use the session to store the user identifiers.
// That's not the best practice, because you should have a logic to identify
// a user. You might want to use "OpenID Connect".
// You can read more about the protocol in the following link:
// https://developers.google.com/accounts/docs/OAuth2Login.
var user = controller.Session["user"];
if (user == null)
{
user = Guid.NewGuid();
controller.Session["user"] = user;
}
return user.ToString();
}
public override IAuthorizationCodeFlow Flow
{
get { return flow; }
}