简体   繁体   English

FusionTables HTTP调用与使用JavaScript客户端库(gapi)的调用之间的响应有所不同

[英]Response varies between FusionTables HTTP call and call with JavaScript client library (gapi)

I have a JavaScript client application. 我有一个JavaScript客户端应用程序。 When I call the FusionTables API to retrieve some data through a SQL query using Angular's $http service (essentially XHR underneath) the data I expect is returned correctly: 当我调用FusionTables API通过使用Angular的$ http服务(本质上是XHR)通过SQL查询检索某些数据时,正确返回了我期望的数据:

(Note config.apiKey is my Google API key, verified as correct from the cloud console) (请注意config.apiKey是我的Google API密钥,已从云控制台验证为正确)

$http({
    "method": "GET",
    "url": "https://www.googleapis.com/fusiontables/v1/query",
    "params": {
        "sql": sql,
        "key": config.apiKey
    }
});

Now, when I use the JavaScript client library like so, I get an "Access Not Configured" error: 现在,当我像这样使用JavaScript客户端库时,出现“未配置访问”错误:

(earlier...) (较早...)

gapi.client.setApiKey(config.apiKey);

gapi.client.load("fusiontables", "v1")

(note this has a callback which defers code execution until it has successfully loaded) (请注意,这有一个延迟执行代码直到成功加载代码的回调)

gapi.client.fusiontables.query.sql({
    "sql": sql
}).execute(function(data) {
    future.resolve(data);
});

This results in data containing: 这导致数据包含:

{
    "code": 403,
    "message": "Access Not Configured",
    "data": [
        {
            "domain": "usageLimits",
            "reason": "accessNotConfigured",
            "message": "Access Not Configured"
        }
    ],
    "error": {
        "code": 403,
        "message": "Access Not Configured",
        "data": [
            {
                "domain": "usageLimits",
                "reason": "accessNotConfigured",
                "message": "Access Not Configured"
            }
        ]
    }
}

Under the hood it appears to use some kind of JSON RPC format for calling the API so perhaps there is a difference there. 在幕后似乎使用了某种JSON RPC格式来调用API,因此可能有所不同。 The documentation for accessing fusion tables through the client library seems to have disappeared in the transition to the new developers.google.com which doesn't seem to help. 通过客户端库访问融合表的文档似乎在向新的developers.google.com过渡的过程中消失了,这似乎无济于事。

Any suggestions as to how to properly configure this or even debug it a bit would be most welcome. 任何有关如何正确配置甚至调试它的建议都将受到欢迎。

Update: 更新:

I am using the G+ version of client.js (called client:plusone.js) because I need to render Google+ buttons. 我使用的是Google+的G +版本(称为client:plusone.js),因为我需要渲染Google+按钮。 When I am logged in, I get an insufficient permission warning (even when setting the API key), so I am thinking this is a conflict between the Fusion Tables client and the Google+ client - I'm trying to find out if there is a way to specify the auth method to use but it appears not. 登录后,我收到的权限警告不足(即使设置API密钥也是如此),因此我认为这是Fusion Tables客户端和Google+客户端之间的冲突-我试图找出是否存在指定要使用的auth方法的方法,但似乎没有。

Try setting the API key in the onload callback of the API. 尝试在API的onload回调中设置API密钥。 For instance, the generated code for published heatmaps has this (for a dummy API key, of course): 例如,为发布的热图生成的代码具有以下内容(当然,对于虚拟API密钥):

<script type="text/javascript">
  function ftOnLoadClientApi() {
    gapi.client.setApiKey('xyzabc');
  }
</script>
<script type="text/javascript" src="//apis.google.com/js/client.js?onload=ftOnLoadClientApi">
</script>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM