使用嵌入 API 谷歌分析设置 API 密钥 [英] Set API key with embed API google analytics

查看:28
本文介绍了使用嵌入 API 谷歌分析设置 API 密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 embed api 使用我的谷歌分析数据绘制地图:

<前>(功能(w,d,s,g,js,fs){g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};js=d.createElement(s);fs=d.getElementsByTagName(s)[0];js.src='https://apis.google.com/js/platform.js';fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};}(窗口,文档,'脚本'));gapi.analytics.auth.authorize({服务器验证:{access_token: '我的访问令牌'})};var commonConfig2 = {询问: {ids: 'ga:' + gaViewId,指标:'ga:users',尺寸:'ga:区域','最大结果':5,排序:'-ga:用户'},图表: {类型:'地理',容器:'时间线',选项: {显示模式:'标记',宽度:'100%'}}};var dataChart3 = new gapi.analytics.googleCharts.DataChart(commonConfig2).set({查询: dateRange1}).set({chart: {container: 'chart-3-container'}});

地图渲染良好.但是几天前我收到错误Google Maps API 错误:MissingKeyMapError"并且地图不再呈现.经过一番谷歌搜索后,我才知道谷歌现在需要 Api 密钥才能访问其 api.如何使用现有代码设置 api 密钥.

解决方案

这需要通过电子邮件与 Google 团队来回交流.

Maps API 似乎发生了变化,现在需要您发送密钥才能访问它.

嵌入式 API 并非旨在允许您发送假定不需要的密钥.

状态:目前没有人在开发嵌入式 API,并且它的代码不是开源的.嵌入式 API 中的地图已损坏,直至另行通知.我的 Google 联系人无法告诉我将来何时或是否会修复此问题.

I was rending map with my google analytics data using embed api as:


    (function(w,d,s,g,js,fs){
      g=w.gapi||(w.gapi={});g.analytics={q:[],ready:function(f){this.q.push(f);}};
      js=d.createElement(s);fs=d.getElementsByTagName(s)[0];
      js.src='https://apis.google.com/js/platform.js';
      fs.parentNode.insertBefore(js,fs);js.onload=function(){g.load('analytics');};
    }(window,document,'script'));

    gapi.analytics.auth.authorize({
       serverAuth: {
           access_token: 'my access token' 
        }
    )};

    var commonConfig2 = {
       query: {
           ids: 'ga:' + gaViewId,
           metrics: 'ga:users',
           dimensions: 'ga:region',
           'max-results': 5,
           sort : '-ga:users'   
        },
           chart: {
           type: 'GEO',
           container: 'timeline',
           options: {
              displayMode: 'markers',
              width: '100%' 
           }
        }
    };

    var dataChart3 = new gapi.analytics.googleCharts.DataChart(commonConfig2)
          .set({query: dateRange1})
          .set({chart: {container: 'chart-3-container'}});

Map was rendering fine. But few days back i got error "Google Maps API error: MissingKeyMapError" and map is no longer rending. After some googling i came to know that google now require Api key to access its api. How can i set api key with my existing code.

解决方案

This took a little emailing back and forth with the team at Google.

It appears that the Maps API has changed and now requires that you send an key to access it.

The embedded API was not designed to allow you to send a key it assumed that one was not needed.

Status: At this time no one is working on the Embedded API and the code for it is not open source. Maps in the Embedded API are broken until further notice. My Google contact was unable to tell me when or if it would be fixed in the future.

这篇关于使用嵌入 API 谷歌分析设置 API 密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆