【发布时间】:2016-06-09 18:24:49
【问题描述】:
我正在为我的公司创建一个网络/应用程序(在我的空闲时间),为我们的客户提供访问权限,以检索和回复我们为他们发布的应用程序的谷歌评论。 谷歌已经发布了一个Reply to Reviews API 应该可以解决这个问题。
我无法弄清楚“获得访问权限”部分。
我正在尝试使用服务帐户。我创建了一个 OAuth2 服务帐户,授予访问权限,下载了一个私钥,并且厌倦了遵循here(下)提供的示例。
我知道在示例中它使用的是 Plus 服务。 我的问题是,我应该使用什么服务?我假设 plus 服务不是我想要的。
以这种方式生成证书是否是获取 auth_token 的正确方法(在回复评论 API 文档中)?
感谢您的帮助!
using System;
using System.Security.Cryptography.X509Certificates;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Plus.v1;
using Google.Apis.Plus.v1.Data;
using Google.Apis.Services;
namespace Google.Apis.Samples.PlusServiceAccount
{
/// <summary>
/// This sample demonstrates the simplest use case for a Service Account service.
/// The certificate needs to be downloaded from the Google Developers Console
/// <see cref="https://console.developers.google.com/">
/// "Create another client ID..." -> "Service Account" -> Download the certificate,
/// rename it as "key.p12" and add it to the project. Don't forget to change the Build action
/// to "Content" and the Copy to Output Directory to "Copy if newer".
/// </summary>
public class Program
{
// A known public activity.
private static String ACTIVITY_ID = "z12gtjhq3qn2xxl2o224exwiqruvtda0i";
public static void Main(string[] args)
{
Console.WriteLine("Plus API - Service Account");
Console.WriteLine("==========================");
String serviceAccountEmail = "SERVICE_ACCOUNT_EMAIL_HERE";
var certificate = new X509Certificate2(@"key.p12", "notasecret", X509KeyStorageFlags.Exportable);
ServiceAccountCredential credential = new ServiceAccountCredential(
new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { PlusService.Scope.PlusMe }
}.FromCertificate(certificate));
// Create the service.
var service = new PlusService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Plus API Sample",
});
Activity activity = service.Activities.Get(ACTIVITY_ID).Execute();
Console.WriteLine(" Activity: " + activity.Object.Content);
Console.WriteLine(" Video: " + activity.Object.Attachments[0].Url);
Console.WriteLine("Press any key to continue...");
Console.ReadKey();
}
}
}
【问题讨论】:
标签: android api google-play google-play-services google-play-developer-api