我无法使用服务凭据模型连接到Google Apps转销商API(适用于.NET)。
关于我哪里出错的任何想法?
步骤:
来源:
=====================
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.");
}
}
}
}