认证请求执行返回意外的结果:404 [英] Execution of authentication request returned unexpected result: 404

查看:213
本文介绍了认证请求执行返回意外的结果:404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用 Google.GData.Analytics Google.GData.Client 检索在我的Web应用程序,虽然谷歌Analytics API V2一些谷歌Analytics的数据。

I have been using the Google.GData.Analytics and Google.GData.Client to retrieve some Google Analytics data though the Google Analytics API v2 in my web application.

在code如下:

string username = "abc@gmail.com";
        string password = "myPasswordHere";
        string profileId = "ga:88376970";
        string _from = Convert.ToDateTime(dtpFrom.SelectedDate.Value.ToString()).ToString("yyyy-MM-dd");
       string _to = Convert.ToDateTime(dtpTo.SelectedDate.Value.ToString()).ToString("yyyy-MM-dd");
        AccountQuery AccountsQuery = new AccountQuery();
        service = new AnalyticsService("DoogalAnalytics");
        service.setUserCredentials(username, password);
        try
        {
            DataFeedUrl = "https://www.google.com/analytics/feeds/data";
            DataQuery PageViewQuery = new DataQuery(DataFeedUrl)
            {
                Ids = profileId ,
                Metrics = "ga:pageviews",
                Dimensions = "ga:date",
                Sort = "ga:date",
                GAStartDate = _from,
                GAEndDate = _to
            };
            StringBuilder strData = new StringBuilder();
            int maxValue = 0;
            int today = 0;
            List<int> gList = new List<int>();                
            foreach (DataEntry entry in service.Query(PageViewQuery).Entries)
            {
                var value = entry.Metrics.First().IntegerValue;
                gList.Add(value);
                maxValue = value > maxValue ? value : maxValue;
                today = entry.Metrics.Last().IntegerValue;
                strData.AppendFormat("{0},", value);
            }

        }
        catch (Exception ex)
        {
            Response.Write(ex.Message.ToString());
        }

这code的工作完全正常,直到5天前,我一直在用这个code在过去的7或8个月,但现在突然我对着误差

This code was working perfectly fine until about 5 days ago and I have been using this code for the last 7 or 8 months, but now suddenly I am facing the error

的认证请求执行返回意想不到的结果:404

Execution of authentication request returned unexpected result: 404.

当我搜索谷歌。 我搜索了很多,但找不到任何解决办法。 任何帮助或指导将大大AP preciated。

When I searched google. I have searched alot but could not find any solution. Any help or guidance will be greatly appreciated.

推荐答案

客户端而被中断/关机登录开始了的二零一五年四月二十○日并大概在5月26日2015年,您不能再使用客户端登录(登录名和密码)与谷歌Analytics API完成,你需要切换到Oauth2。你需要改变你的code使用Oauth2或服务帐户。

Client login which was discontinued / shutdown began on April 20 2015 and probably completed around May 26 2015. You can no longer use client login (Login and password) with the Google Analytics API, you need to switch to Oauth2. You will need to change your code to use Oauth2 or a service account.

其最抢它使用你正在使用V2谷歌Analytics(分析)V3客户端库的最新版本。

Its best to grab the newest version of the client library which uses Google Analytics V3 you are using V2.

PM>安装,包装Google.Apis.Analytics.v3

如果这是你已经拥有你可能要考虑服务帐户数据。服务帐户可以让你设置访问你的谷歌Analytics帐户,它不会要求用户进行身份验证您的code。如果这不是你的谷歌Analytics帐户,但实际上一个接其他用户所拥有,那么你就需要从用户使用Oauth2并请求验证。

If this is data you already own you may want to consider a service account. A service account will let you set up access to your google analytics account and it wont require a user to authenticate your code. If this is not your Google Analytics account but in fact one owned by another user then you will need to use Oauth2 and request authentication from the user.

我的教程:谷歌Analytics(分析)API认证用C#

code从教程撕开上面的教程不断更新这个code可能没有:

Code ripped from tutorial above the tutorial is kept up to date this code may not be:

    string[] scopes = new string[] {
            AnalyticsService.Scope.Analytics,  // view and manage your Google Analytics data
            AnalyticsService.Scope.AnalyticsEdit,  // Edit and manage Google Analytics Account
            AnalyticsService.Scope.AnalyticsManageUsers,   // Edit and manage Google Analytics Users
            AnalyticsService.Scope.AnalyticsReadonly};     // View Google Analytics Data

    String CLIENT_ID = "6.apps.googleusercontent.com"; // found in Developer console
    String CLIENT_SECRET = "xxx";// found in Developer console
    // here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
    UserCredential credential = 
            GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { 
                                                           ClientId = CLIENT_ID
                                                           , ClientSecret = CLIENT_SECRET 
                                                           }
                                                        , scopes
                                                        , Environment.UserName
                                                        , CancellationToken.None
                                                        , new FileDataStore("Daimto.GoogleAnalytics.Auth.Store")).Result;

AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer()
            {
             HttpClientInitializer = credential,
             ApplicationName = "Analytics API Sample",
            });

DataResource.GaResource.GetRequest request = service.Data.Ga.Get("ga:8903098", "2014-01-01", "2014-01-01", "ga:sessions");
request.MaxResults = 1000;
GaData result = request.Execute();

这篇关于认证请求执行返回意外的结果:404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆