Google.GoogleApiException未被用户代码处理

时间:2015-08-03 14:45:39

标签: google-reseller-api

我无法使用服务凭据模型连接到Google Apps转销商API(适用于.NET)。

关于我哪里出错的任何想法?

步骤:

  1. 在Google开发者控制台中创建服务应用程序
  2. 启用的API(Admin SDK; BigQuery API; Debuglet控制器API;企业版;许可证管理器API; Google Apps转销商API; Google Cloud Logging API; Google Cloud SQL; Google云端存储; Google云端存储JSON API;网站验证API)
  3. 在Google应用域(转销商域)
  4. 上创建了API权限

    来源:

    =====================

    function initSlider(){
        $('.references').slick({
            dots: false,
            infinite: true,
            speed: 300,
            slidesToShow: 1,
            autoplay: true,
            prevArrow: '<div class="slick-prev"><i class="fa fa-chevron-left"></i></div>',
            nextArrow: '<div class="slick-next"><i class="fa fa-chevron-right"></i></div>'
        });
    }
    
    $(document).on('ready', function () {
        initSlider();
    });
    

    应用程序错误:

    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Reseller.v1;
    using Google.Apis.Reseller.v1.Data;
    using Google.Apis.Services;
    using Google.Apis.Util.Store;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Threading.Tasks;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Security.Cryptography.X509Certificates;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Services;
    
    namespace GoogleApiWeb
    {
        public partial class _Default : Page
        {
    
            static string ApplicationName = "Testing API";
            protected void Page_Load(object sender, EventArgs e)
            {
    
                String serviceAccountEmail = "...removed...@developer.gserviceaccount.com";
    
                var certificate = new X509Certificate2(@"C:\\Dev\\GoogleApiWeb\\GoogleApiWeb\\TestingResellerAPI-6555.p12", "notasecret", X509KeyStorageFlags.Exportable);
    
                ServiceAccountCredential credential = new ServiceAccountCredential(
                   new ServiceAccountCredential.Initializer(serviceAccountEmail)
                   {
                       Scopes = new[] { ResellerService.Scope.AppsOrder }
                   }.FromCertificate(certificate));
    
                // Create Google Apps Reseller API service.
                var service = new ResellerService(new BaseClientService.Initializer()
                {
                    HttpClientInitializer = credential,
                    ApplicationName = ApplicationName,
                });
    
                // Define parameters of request.
                SubscriptionsResource.ListRequest request = service.Subscriptions.List();
                request.MaxResults = 10;
    
                // List subscriptions.
                IList<Subscription> subscriptions = request.Execute().SubscriptionsValue;
                Response.Write("<p>Subscriptions:</p>");
                if (subscriptions != null && subscriptions.Count > 0)
                {
                    foreach (var subscription in subscriptions)
                    {
                        {
                            Response.Write(subscription.CustomerId.ToString());
                            Response.Write(": ");
                            Response.Write(subscription.SkuId.ToString());
                            Response.Write(" ");
                            Response.Write(subscription.Plan.PlanName.ToString());
                            Response.Write('\n');
                        }
                    }
                }
                else
                {
                    Response.Write("No subscriptions found.");
                }
    
            }
        }
    }
    

0 个答案:

没有答案