如何导入angular 4和spring boot的联系人列表?有没有免费的api'';s

如何导入angular 4和spring boot的联系人列表?有没有免费的api'';s,angular,spring-boot,Angular,Spring Boot,我想导入联系人列表,如Gmail、Yahoo、Hotmail。我已经找到了关于PHP的信息,但我正在使用angular 4和spring boot。它们只参考了其他技术。让我们看看如何做到这一点 连接我们的谷歌帐户 询问我们需要的“范围” 询问谷歌用户的联系方式 用那些电子邮件做什么(你必须做什么) 1 — 导入javascript库 在index.html内和body标记的en处 <script async defer src="https://apis.google.com/js/pl

我想导入联系人列表,如Gmail、Yahoo、Hotmail。我已经找到了关于PHP的信息,但我正在使用angular 4和spring boot。它们只参考了其他技术。

让我们看看如何做到这一点

  • 连接我们的谷歌帐户

  • 询问我们需要的“范围”

  • 询问谷歌用户的联系方式

  • 用那些电子邮件做什么(你必须做什么)

  • 1 — 导入javascript库

    在index.html内和body标记的en处

    <script async defer src="https://apis.google.com/js/platform.js"></script>
    <script async defer src="https://apis.google.com/js/api.js"></script>
    
    然后您必须像这样加载api:

     ngAfterViewInit(): void {
            setTimeout(() => this.signIn(), 1000);
        }
    
    signIn() {
        gapi.load('auth2', () => {
            this.auth2 = gapi.auth2.init({
                client_id: 'YOUR_CLIENT_ID',
                cookie_policy: 'single_host_origin',
                scope: 'profile email https://www.googleapis.com/auth/contacts.readonly'
            });
            this.auth2.attachClickHandler(document.getElementById('googleres'), {}, this.onSignIn, this.onFailure);
        })
    }
    
    setTimeOut的原因只是为了避免在api完全下载之前尝试加载gapi。1秒钟似乎足够了

    用您在google Developer console/web oauth credential中创建的ID替换您的客户端ID

    看这里,我们现在有我们的按钮链接到我们的谷歌Auth2对象,这意味着我们将登录时,我们点击它

    3-登录并获取电子邮件

    当用户接受时,我们希望这样做:

    onSignIn = (data: any) => {
    
        setTimeout(() => this.fetchmail(), 1000);
    }
    data is containing our token
    
    fetchmail() {
        gapi.load('client:auth2', () => {
            gapi.client.init({
                apiKey: 'API_KEY use your own',
                discoveryDocs: ['https://people.googleapis.com/$discovery/rest?version=v1'],
                clientId: 'YOUR_CLIENT_ID',
                scope: 'profile email https://www.googleapis.com/auth/contacts.readonly'
            }).then(() => {
                return gapi.client.people.people.connections.list({
                    resourceName:'people/me',
                    personFields: 'emailAddresses,names'
                });
            }).then(
                (res) => {
                    //console.log("Res: " + JSON.stringify(res)); to debug
                    this.userContacts.emit(this.transformToMailListModel(res.result));
                },
                error => console.log("ERROR " + JSON.stringify(error))
            );
        });
    
    现在,您有了带有姓名的用户邮件列表。就这么简单


    参考资料:-

    让我们看看我们将如何做到这一点

  • 连接我们的谷歌帐户

  • 询问我们需要的“范围”

  • 询问谷歌用户的联系方式

  • 用那些电子邮件做什么(你必须做什么)

  • 1 — 导入javascript库

    在index.html内和body标记的en处

    <script async defer src="https://apis.google.com/js/platform.js"></script>
    <script async defer src="https://apis.google.com/js/api.js"></script>
    
    然后您必须像这样加载api:

     ngAfterViewInit(): void {
            setTimeout(() => this.signIn(), 1000);
        }
    
    signIn() {
        gapi.load('auth2', () => {
            this.auth2 = gapi.auth2.init({
                client_id: 'YOUR_CLIENT_ID',
                cookie_policy: 'single_host_origin',
                scope: 'profile email https://www.googleapis.com/auth/contacts.readonly'
            });
            this.auth2.attachClickHandler(document.getElementById('googleres'), {}, this.onSignIn, this.onFailure);
        })
    }
    
    setTimeOut的原因只是为了避免在api完全下载之前尝试加载gapi。1秒钟似乎足够了

    用您在google Developer console/web oauth credential中创建的ID替换您的客户端ID

    看这里,我们现在有我们的按钮链接到我们的谷歌Auth2对象,这意味着我们将登录时,我们点击它

    3-登录并获取电子邮件

    当用户接受时,我们希望这样做:

    onSignIn = (data: any) => {
    
        setTimeout(() => this.fetchmail(), 1000);
    }
    data is containing our token
    
    fetchmail() {
        gapi.load('client:auth2', () => {
            gapi.client.init({
                apiKey: 'API_KEY use your own',
                discoveryDocs: ['https://people.googleapis.com/$discovery/rest?version=v1'],
                clientId: 'YOUR_CLIENT_ID',
                scope: 'profile email https://www.googleapis.com/auth/contacts.readonly'
            }).then(() => {
                return gapi.client.people.people.connections.list({
                    resourceName:'people/me',
                    personFields: 'emailAddresses,names'
                });
            }).then(
                (res) => {
                    //console.log("Res: " + JSON.stringify(res)); to debug
                    this.userContacts.emit(this.transformToMailListModel(res.result));
                },
                error => console.log("ERROR " + JSON.stringify(error))
            );
        });
    
    现在,您有了带有姓名的用户邮件列表。就这么简单


    参考资料:-

    不知道是谁对这个问题投了赞成票,但这个问题非常广泛,也不清楚你到底想要什么。您还要求提供非现场资源(API)。很抱歉,我找不到任何资源将这些联系人列表导入这些技术。我已经广泛地搜索过了,但我对spring boot还不熟悉,对angular 4的经验有限。你能建议如何重新表述我的问题吗?问题是(a)你要求的是API,它们是非现场资源。这样的问题是不允许的。(b) 它的范围很广,因为您将范围保持得太广(多个技术,多个提供者)。要解决这个问题,可以选择任何一种技术,或者Gmail、Yahoo……来限制范围。还可以尝试使用在PHP中找到的信息,但是在SpringBoot/Angular中。如果你坚持在Spring boot/Angular中复制同样的东西,那么就要问一个关于你坚持做什么的具体问题。不知道是谁对这个问题投了赞成票,但这个问题非常广泛,也不清楚你到底想要什么。您还要求提供非现场资源(API)。很抱歉,我找不到任何资源将这些联系人列表导入这些技术。我已经广泛地搜索过了,但我对spring boot还不熟悉,对angular 4的经验有限。你能建议如何重新表述我的问题吗?问题是(a)你要求的是API,它们是非现场资源。这样的问题是不允许的。(b) 它的范围很广,因为您将范围保持得太广(多个技术,多个提供者)。要解决这个问题,可以选择任何一种技术,或者Gmail、Yahoo……来限制范围。还可以尝试使用在PHP中找到的信息,但是在SpringBoot/Angular中。如果你在Spring boot/Angular中无法复制相同的东西,那么请问一个关于你无法复制的具体问题。非常感谢!我会努力的。非常感谢你!我试试看。