10
我想用C#中使用谷歌分析嵌入API服務器端授權,代碼如下谷歌Analytics(分析)嵌入API服務器端授權C#
public ActionResult Dashboard()
{
ViewBag.Message = "Dashboard.";
var scopes = new string[]
{
AnalyticsService.Scope.Analytics, // view and manage your Google Analytics data
AnalyticsService.Scope.AnalyticsReadonly,
AnalyticsService.Scope.AnalyticsEdit
};
const string serviceAccountEmail = "[email protected]ccount.com";
const string keyFilePath = @"D:\key.p12";
var status = RequestAccessTokenAsync(keyFilePath,scopes,serviceAccountEmail);
ViewBag.Token = _accessToken;
return View();
}
private async Task<bool> RequestAccessTokenAsync(string certificateFile, string[] scope, string serviceAccount)
{
var certificate = new X509Certificate2(certificateFile, "notasecret", X509KeyStorageFlags.Exportable);
var serviceAccountCredential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccount)
{
Scopes = scope
}.FromCertificate(certificate));
var status = await serviceAccountCredential.RequestAccessTokenAsync(CancellationToken.None);
if (status)
_accessToken = serviceAccountCredential.Token.AccessToken;
return status;
}
製作服務的實例工作正常,也能以獲取原始數據,但我們需要使用Embed API,問題是_accessToken中沒有檢索到值,我們需要能夠訪問嵌入式API。
任何想法/想法都會有所幫助。
在谷歌演示網站,所提供的例子是蟒蛇 - https://ga-dev-tools.appspot.com/embed-api/server-side-authorization/
檢查我的問題在這裏:http://stackoverflow.com/questions/41905074/google-analytics -embed-api-server-side-authorization-not-rendering-the-charts-wi我希望它能幫助你。 – Patrick