【问题标题】:Google Contacts API nodejs谷歌通讯录 API nodejs
【发布时间】:2014-11-24 20:22:43
【问题描述】:

我一直在浏览 Google NodeJS API 文档,但没有看到为联系人 API 列出的文档。是我遗漏了什么还是模块中没有包含什么?

【问题讨论】:

    标签: node.js google-contacts-api google-api-nodejs-client


    【解决方案1】:

    Google 的 NodeJS 官方 API 不使用 Contacts API。他们改用 People API。如果您需要访问“其他联系人”,则需要 Contacts API。

    如果您已经将其用于其他目的,您仍然可以使用 official googleapis library 与联系人 API 连接,方法是在创建身份验证客户端后向联系人 API 发送请求。如果您不使用 googleapis 库,那可能是矫枉过正,最好使用其他答案建议的其他库。

    鉴于您已经拥有用户的访问令牌(例如,如果您使用 Passport 生成它,代码如下:

    const {google} = require("googleapis");
    const authObj = new google.auth.OAuth2({
        access_type: 'offline',
        clientId: process.env.GOOGLE_ID,
        clientSecret: process.env.GOOGLE_SECRET,
    });
    

    访问令牌过期前自动刷新

    authObj.on('tokens', (tokens) => {
        const access_token = tokens.access_token
        if (tokens.refresh_token){
            this.myTokens.refreshToken = tokens.refresh_token
            // save refresh token in the database if it exists
        }
            this.myTokens.accessToken = tokens.access_token       
            // save new access token (tokens.access_token)
    }
    authObj.setCredentials({
        access_token:this.myTokens.accessToken,
        refresh_token:this.myTokens.refreshToken,
    });
    

    向联系人 API 发出请求:

    authObj.request({
        headers:{
            "GData-Version":3.0
        },
        params:{
            "alt":"json",
            //"q":"OPTIONAL SEARCH QUERY",
            //"startindex":0
            "orderby":"lastmodified",
            "sortorder":"descending",
        },
        url: "https://www.google.com/m8/feeds/contacts/default/full"
    }).then( response => {
        console.log(response); // extracted contacts
    });
    

    【讨论】:

      【解决方案2】:

      根据 Google NodeJS API for Google Contacts API,以下链接可能对您有所帮助:

      https://github.com/jimib/nodejs-google-contacts

      https://github.com/elentok/gcontacts

      https://github.com/mattnull/node-googlecontacts

      【讨论】:

      • 谢谢!您在 api 文档中哪里看到的?
      • 我在 doc ether 中没有看到。希望这些链接可以帮助你。
      • 好的,np,它确实做到了~
      猜你喜欢
      • 2014-12-02
      • 2015-05-31
      • 2012-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-11
      • 2016-01-03
      • 1970-01-01
      相关资源
      最近更新 更多