{"Unexpected character encountered while parsing a value: <. Path '', line 0, position 0." } in google analytics api

Im using sample code from GitHub.

            #region code

            AnalyticsService service;

                       // Service account Authentication 
            String SERVICE_ACCOUNT_EMAIL =" ";// removed the account email
            string SERVICE_ACCOUNT_KEYFILE = @"C:\Projects\Test\TMBWebsite-7f016e7c3562.p12";
            service = DaimtoAnalyticsAuthenticationHelper.AuthenticateServiceAccount(SERVICE_ACCOUNT_EMAIL,SERVICE_ACCOUNT_KEYFILE);




            //////Get account summary and display them.
            foreach (AccountSummary account in DaimtoAnaltyicsManagmentHelper.AccountSummaryList(service).Items)
            {
                // Account
                Console.WriteLine("Account: " + account.Name + "(" + account.Id + ")");

                foreach (WebPropertySummary wp in account.WebProperties)
                {

                    // Web Properties within that account
                    Console.WriteLine("\tWeb Property: " + wp.Name + "(" + wp.Id + ")");


                    //Don't forget to check its not null. Believe it or not it could be.  
                    if (wp.Profiles != null)
                    {

                        foreach (ProfileSummary profile in wp.Profiles)
                        {
                            // Profiles with in that web property.
                            Console.WriteLine("\t\tProfile: " + profile.Name + "(" + profile.Id + ")");
                        }
                    }
                }
            }

            #endregion

      

// Authenticate the service

        if (!File.Exists(keyFilePath))
        {
            Console.WriteLine("An Error occurred - Key file does not exist");
            return null;    
        }

        string[] scopes = new string[] { AnalyticsService.Scope.Analytics,  // view and manage your analytics data
                                         AnalyticsService.Scope.AnalyticsEdit,  // edit management actives
                                         AnalyticsService.Scope.AnalyticsManageUsers,   // manage users
                                         AnalyticsService.Scope.AnalyticsReadonly};     // View analytics data            

        X509Certificate2 certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
       // X509Certificate2 certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);
        try
        {
            ServiceAccountCredential credential = new ServiceAccountCredential(
                new ServiceAccountCredential.Initializer(serviceAccountEmail)
               {
                   Scopes = scopes
               }.FromCertificate(certificate));

            // Create the service.
            AnalyticsService service = new AnalyticsService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = "Analytics API Sample",
            });
            return service;
        }
        catch (Exception ex)
        {

            Console.WriteLine(ex.InnerException);
            return null;

        }

      

# Account registration

    /// <summary>
    /// Lists account summaries (lightweight tree comprised of accounts/properties/profiles) to which the user has access.
    /// Documentation: https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountSummaries/list
    /// </summary>
    /// <param name="service">Valid authenticated Analytics Service</param>
    /// <returns>List of Account Summaries resource - https://developers.google.com/analytics/devguides/config/mgmt/v3/mgmtReference/management/accountSummaries</returns>
    public static AccountSummaries AccountSummaryList(AnalyticsService service)
    {

        //List all of the activities in the specified collection for the current user.  
        // Documentation: https://developers.google.com/+/api/latest/activities/list

        //ManagementResource.AccountSummariesResource.ListRequest list = service.Management.AccountSummaries.List();
        ManagementResource.AccountSummariesResource.ListRequest list = service.Management.AccountSummaries.List();
        list.Alt = ManagementResource.AccountSummariesResource.ListRequest.AltEnum.Json;
        list.MaxResults = 1000;  // Maximum number of Account Summaries to return per request. 

        AccountSummaries feed = list.Execute();
        List<AccountSummary> allRows = new List<AccountSummary>();

        //var getRequest = settingsService.Groups.Get("[email protected]");
        //getRequest.Alt = "json";
        //var settings = getRequest.Execute();

        //// Loop through until we arrive at an empty page
        while (feed.Items != null)
        {

            allRows.AddRange(feed.Items);

            // We will know we are on the last page when the next page token is
            // null.
            // If this is the case, break.
            if (feed.NextLink == null)
            {
                break;
            }

            // Prepare the next page of results             
            list.StartIndex = feed.StartIndex + list.MaxResults;
            // Execute and process the next page request
            feed = list.Execute();

        }

        feed.Items = allRows;

        return feed;

    }
    #endregion

      

AccountSummaries feed = list.Execute (); throws an exception: {"Unexpected character encountered while parsing a value: <. Path '', line 0, position 0." } in google analytics api

+3


source share


1 answer


I understood that. The firewall was blocking my request. Added below mentioned code to my config file and it worked <system.net> <defaultProxy useDefaultCredentials="true"> <proxy proxyaddress="My proxy address here" usesystemdefault="True"/> </defaultProxy> </system.net>



+2


source







All Articles