0

これが私がやろうとしていることです。データベースから資格情報を含むサインインページを含むWebページを取得しました。ログインすると、グラフにデータが表示されるメインページにリダイレクトされます。

問題は、gdata v2.4 を使用したことですが、リクエストを行うたびに資格情報を再度設定する必要があり、oauth 2.0 を使用する v3.0 では、アクセス トークンによってこれを行う必要はもうないと言われました。

私はそれを機能させることができましたが、問題は、ユーザーがGmailアカウントでログインするように求められ、電子メールとパスワードがリクエストのプロファイルIDと一致しない場合、403エラー(アクセス禁止)が発生することです。これはコードです. 私はサービスアカウントを使用しようとしましたが、問題は何ですか?

 log4net.Config.XmlConfigurator.Configure();
    //string Scope = AnalyticsService.Scopes.Analytics.ToString().ToLower();
    //string scopeUrl = "https://www.google.com/analytics/feeds/" + Scope;
    string Scope = "https://www.google.com/analytics/feeds/";
    const string ServiceAccountId = "xxxxxxxxxxx.apps.googleusercontent.com";
    const string ServiceAccountUser = "xxxxxxxxxxx@developer.gserviceaccount.com";
    string key = string.Empty;
    foreach (string keyname in Directory.GetFiles(Server.MapPath("/"), "*.p12", SearchOption.AllDirectories))
    {
        key = keyname;
    }

    AssertionFlowClient client = new AssertionFlowClient(
        GoogleAuthenticationServer.Description, new X509Certificate2(key, "notasecret", X509KeyStorageFlags.Exportable))
    {
     Scope = Scope,   
        ServiceAccountId = ServiceAccountUser//,ServiceAccountUser = ServiceAccountUser
    };
      WebServerClient myWebServerClient = new WebServerClient(GoogleAuthenticationServer.Description);
    myWebServerClient.ClientIdentifier = this.ClientID;
    myWebServerClient.ClientSecret = this.ClientSecret;
    OAuth2Authenticator<WebServerClient> authenticator = new OAuth2Authenticator<WebServerClient>(myWebServerClient, GetAuthorization);

    AnalyticsService service = new AnalyticsService(authenticator);
    string profileId = Session["_ProfileID"].ToString() ;
    string startDate = StartDate;
    string endDate = EndDate;
    string metrics = "ga:visits";
    DataResource.GaResource.GetRequest request = service.Data.Ga.Get(profileId, startDate, endDate, metrics);
    request.Dimensions = "ga:date";
    request.StartIndex = 1;
    request.MaxResults = 500;
    GaData data = request.Fetch();
    return data;
4

1 に答える 1

0

もう気にしないでください。オフライン アクセスで問題が解決しました。サポートを表示していただきありがとうございます

于 2013-01-17T12:58:31.260 に答える