【问题标题】:Google FusionTable - Google API for .NetGoogle FusionTable - 适用于 .Net 的 Google API
【发布时间】:2015-06-04 21:35:40
【问题描述】:

我们正在尝试使用适用于 .Net 的 Google Api 访问/更新 google 融合表。我们下载了 .Net API,下面是代码。我们能够获取表信息,但不能执行任何 sql 查询。它们都返回错误“Forbidden [403]”。请查看并指出我们的错误:

这是错误信息:

{
"error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Forbidden"
   }
  ],
  "code": 403,
  "message": "Forbidden"
}
}

以下是代码:

    using Google.Apis.Auth;
    using Google.Apis.Fusiontables;
    using Google.Apis.Auth.OAuth2;
    using Google.Apis.Fusiontables.v2;
    using Google.Apis.Services;
    using Google.Apis.Fusiontables.v2.Data;

    var tableID = "TABLE ID";
    var serviceAccountEmail = "id@developer.gserviceaccount.com";
    var certificate = new X509Certificate2(@"..\App_Data\API Project-d000b00dd0b0.p12", "notasecret", X509KeyStorageFlags.Exportable);

    ServiceAccountCredential credential = new ServiceAccountCredential(
       new ServiceAccountCredential.Initializer(serviceAccountEmail)
       {
           Scopes = new[] { FusiontablesService.Scope.Fusiontables }
       }.FromCertificate(certificate));

    FusiontablesService fusiontablesService = new FusiontablesService(new BaseClientService.Initializer()
    {
        HttpClientInitializer = credential,
        ApplicationName="Test"
    });

    Table tableData = fusiontablesService.Table.Get(tableID).Execute();  **//This code executes fine and we get back the table info(all column names).**

    Try  **//The Execute query throws error ‘403 – Forbidden’** 
    {
        string query = "delete from " + tableID + " where ROWID = '407';";                
        var response = fusiontablesService.Query.Sql(query).Execute();
    }
    catch (Exception ex)
    {
        LogMessageToFile(ex.ToString());
    }

    Try **//The Execute query throws error ‘403 – Forbidden’**
    {
        string query = "update " + tableID + " SET Name = 'OU Pharmacy', Address = '1200 N Phillips Suite 2100 Oklahoma City OK 73104', Coordinates = '35.4792635,-97.4976772', lat = '35.4792635', lng = '-97.4976772', Phone = '405-271-2156', SFlg = '1', Marker = 'red_blank', Type = 'IIAS' where ROWID = '422';";
        var response = fusiontablesService.Query.Sql(query).Execute();
    }
    catch (Exception ex)
    {
        LogMessageToFile(ex.ToString());
    }

    Try **//The Execute query throws error ‘403 – Forbidden’**
    {
        string query = "insert into " + tableID + " (Lid, Name, Address, Coordinates, lat, lng, Phone, SFlg, Type, Marker) values ('10','Bell Pharmacy','113 Boyer Ave. P.O. Box 888 Lincoln AR 72744','35.9493900,-94.4242120','35.9493900','-94.4242120','','1','NTY','grn_blank');";
        var response = fusiontablesService.Query.Sql(query).Execute();
    }
    catch (Exception ex)
    {
        LogMessageToFile(ex.ToString());
    }

谢谢, 阿伦

【问题讨论】:

    标签: google-fusion-tables google-api-dotnet-client


    【解决方案1】:

    我从不使用 fusion-tables,但一般来说,要使用服务帐户访问 google 数据,您还需要启用对服务帐户的所需权限。

    为了启用权限,您需要使用管理帐户登录,然后使用administrator console,您可以使用安全性->(显示更多)高级->管理 API 客户端访问添加所需的权限(另请参阅here) . Here你可以找到grand所需的权限。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-31
      相关资源
      最近更新 更多