0

我正在尝试使用MQLWrite写信给 Freebase 。我设法使用 Freebase Query 进行编写。我输入网址并收到一条错误消息

需要登录

我正在使用 C#。

另一件事是我不需要用户同意。我在 Google Developer 控制台中创建了一个服务帐户,并尝试使用此 url 中的以下代码:

https://code.google.com/p/google-api-dotnet-client/source/browse/Plus.ServiceAccount/Program.cs?repo=samples&r=406dd0081ca556a81621b910eac4445e3309ad1e&spec=svn.samples.406dd0081ca556a81621b910eac4445e3309ad1e

 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();
        }
    }
  1. 我不知道 ACTIVITY_ID 是什么意思,和 CLIENT_ID 一样吗?
  2. 在上面的示例中,他们使用 plus,但我想使用 Freebase,并且在命名空间中的任何位置都找不到 scope 属性。感谢任何帮助... :)
4

1 回答 1

1

从文档:

MQL 写入需要授权。确保您的身份验证工作正常

您的应用程序必须使用 OAuth 2.0 来授权请求​​。不支持其他授权协议。

使用 MQL 写入

MQL Write 支持写入 Freebase 的遗留开发人员应用程序。为了使用 MQL 写入,开发人员必须联系 Freebase 并使用MQL 写入配额访问请求表申请额外配额。

到目前为止,我只能使用公共访问密钥进行访问。

// Simple API example  
// Public API access = is from developer console its different then OAuth. (its at the bottom)

var service = new FreebaseService(new BaseClientService.Initializer
            {
                ApplicationName = "Discovery Sample",
                ApiKey = "{Public API access}",
            });

Google.Apis.Auth用于 OAuth 访问的 Nuget 包似乎丢失了。API 不支持 Oauth 访问,因为文档声明您需要 Oauth 才能访问写入功能。或者 NuGet 包有问题。

您可以尝试对此进行写入吗?看看它是否有效。

于 2014-12-08T10:43:49.247 回答