我正在爲我的公司(在我的空閒時間)創建一個網絡/應用程序,爲我們的客戶提供訪問權限,以檢索並回復我們爲他們發佈的應用程序的Google評論。 Google已發佈Reply to Reviews API這應該爲此工作。回覆來評論API | Google Play開發者API
我一直無法弄清楚獲取訪問部分。
我正在嘗試使用服務帳戶。我創建了一個OAuth2服務帳號,授予訪問權限,下載了一個私鑰,並且按照提供的樣本here(如下)累了。
我知道在這個例子中它使用的是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();
}
}
}
對不起,我應該提到我試圖在C#中做到這一點。你知道使用C#來完成這個任務嗎? –
所以我有了使用Java的Github示例。在Reply to Reviews API文檔中,它說要檢索一組評論: 「使用GET方法爲您的應用程序請求評論列表。在您的請求中,爲您的應用程序添加完全限定的軟件包名稱,例如com.google.android.apps.maps-以及您在獲得API訪問權時獲得的授權令牌。「 GET GET https://www.googleapis.com/androidpublisher/v2/applications/your_package_name/reviews? access_token = your_auth_token' **什麼是授權令牌?** @noogui –