使用AngularFire2使用GAPI访问Google Analytics报告的任何指针 [英] Any pointers on using AngularFire2 With GAPI to Access Google Analytics Reporting

查看:134
本文介绍了使用AngularFire2使用GAPI访问Google Analytics报告的任何指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Angular2:RC4



Firebase :Firebase3(最新版)



AngularFire:
AngularFire2(最新版)



我试图访问Google Analytics(分析)报告v4 API。像。但是使用Angular2的善良。

有没有人有这样做的运气?我用Google搜索了一下,但似乎并没有那么受欢迎。 Angular2还不是很新,所以就是这样。有没有人有任何想法?我确定这是一件事情。我认为?

我已经使用了AngularFire2和Firebase进行身份验证,这是第一步。 ;)

解决方案

这是我实现它的方式:

src / index.html



在您的应用程序的index.html文件中,您需要将其添加到< head>


$ b

 < script src =https://apis.google。 com / js / platform.jsasync defer>< / script> 






typings / browser / ambient / gapi / h1>

您需要将以下命名空间添加到类型中:



还等待拉取请求 p>


$ b

src / app / + login / login.component.ts



这是我的组件的文件,在这里你需要使用 ngAfterViewInit()来使用ga例如,这是我的身份验证功能,我也将API回调转换为承诺:
$
$ b


$ b

b $ b

private authorize():Promise< any> {
var authCallback;
让authData = {
client_id:'your-client-id.apps.googleusercontent.com',
scope:['https://www.googleapis.com/auth/analytics。 readonly'],
immediate:true
};

let p = new Promise((resolve,reject)=> {
authCallback = response => response.error?reject(response):resolve(response);
});

gapi.auth.authorize(authData,authCallback);

return p;
}


Angular: Angular2 RC4

Firebase: Firebase3 (latest)

AngularFire: AngularFire2 (latest)

I'm looking at trying to access the Google Analytics Reporting v4 API. Something like this. But using Angular2 goodness.

Has anyone had any luck with doing this? I've googled, but it doesn't seem to be that popular of a topic. It doesn't help that Angular2 is still pretty new, so there's that. Does anyone have any idea? I'm sure it's a thing. I think?

I've got authentication working with AngularFire2 and Firebase, that's a first step. ;)

解决方案

This was my way of implementing it:

src/index.html

In the index.html file of your app you need to add this in the <head> section:

<script src="https://apis.google.com/js/platform.js" async defer></script>


typings/browser/ambient/gapi/

You need to add the following namespaces to your typings:

Also pending of a pull request:

src/app/+login/login.component.ts

This is the file of my component, here you need to use the ngAfterViewInit() to use the gapi an get the auth.

As an example, this is my auth function where I also transform the API callback into a promise:

private authorize() : Promise<any> {
    var authCallback;
    let authData = {
        client_id: 'your-client-id.apps.googleusercontent.com',
        scope: ['https://www.googleapis.com/auth/analytics.readonly'],
        immediate: true
    };

    let p = new Promise((resolve,reject) => {
      authCallback = response => response.error? reject(response) : resolve(response);
    });

    gapi.auth.authorize(authData, authCallback);

    return p;
}

这篇关于使用AngularFire2使用GAPI访问Google Analytics报告的任何指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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