1
我嘗試寫一些代碼,通過從谷歌的.NET/C#API獲取谷歌Analytics的數據,谷歌分析.NET API的OAuth編譯錯誤
我用下面的話題開始:stack overflow thread
,並寫了下面的代碼
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlTypes;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Authentication.OAuth2;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Analytics.v3;
namespace ManagementAPI.Models
{
public class Value
{
public Guid SiteID { get; set; }
public Guid WidgetID { get; set; }
public string NewValue { get; set; }
public DateTime updateTime { get; set; }
public string GaRefreshToken { get; set; }
public string GaAccesToken { get; set; }
public string GaAccountName { get; set; }
public void getGaValue()
{
var client = new WebServerClient(GoogleAuthenticationServer.Description, "319907436177.apps.googleusercontent.com", "rIir_V4IWcckC0QoDX3gZLYd");
var auth = new OAuth2Authenticator<WebServerClient>(client, Authenticate);
var asv = new AnalyticsService(auth);
var request = asv.Data.Ga.Get("ga:" + GaAccountName, "2012-01-01", "2012-02-20", NewValue);
request.Dimensions = "ga:pagePath";
request.Sort = "-ga:visitors";
request.MaxResults = 5;
var report = request.Fetch();
Console.ReadLine();
NewValue = "TEST";
}
private static IAuthorizationState Authenticate(WebServerClient client)
{
IAuthorizationState state = new AuthorizationState(new string[] { }) { RefreshToken = "REFRESH_TOKEN" };
client.RefreshToken(state);
return state;
}
}
但是當我嘗試編譯此我得到以下錯誤:
Error 1 The best overloaded method match for 'Google.Apis.Analytics.v3.AnalyticsService.AnalyticsService(Google.Apis.Services.BaseClientService.Initializer)' has some invalid arguments H:\vs12\ManagementAPI\ManagementAPI\Models\Value.cs 27 23 ManagementAPI
Error 2 Argument 1: cannot convert from 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator<DotNetOpenAuth.OAuth2.WebServerClient>' to 'Google.Apis.Services.BaseClientService.Initializer' H:\vs12\ManagementAPI\ManagementAPI\Models\Value.cs 27 44 ManagementAPI
我也嘗試「修復」其他線程中描述的api dll,但這不會編譯。
我想發佈這個作爲對其他答案的評論,但因爲我不能,我嘗試用一個新的問題做到這一點。
編輯:使用了錯誤的版本,但仍然不會編譯。
你可以給我一些參考,其中該認證進度被指定爲每最近的圖書館。很難找到用於此的代碼示例。特別是WebServerClient類在哪裏? – 2013-05-26 11:35:23