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

查看:477
本文介绍了通过嵌入API谷歌分析设置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');};
}(window,文件, '脚本'));

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'
},
图表:{
type:' GEO',
container:'timeline',
options:{
displayMode:'markers',
width:'100%'
}
}
};
$ b $ var dataChart3 = new gapi.analytics.googleCharts.DataChart(commonConfig2)
.set({query:dateRange1})
.set({chart:{container:'chart -3-容器'}});

地图渲染正常。但是,几天前,我收到了错误Google Maps API错误:MissingKeyMapError,地图不再呈现。谷歌搜索后,我才知道谷歌现在需要Api键来访问它的api。我怎样才能用我现有的代码来设置API密钥呢? 解决方案

这和Google团队来回发送了一些电子邮件。

似乎Google地图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天全站免登陆