首页 > 解决方案 > 我在 Google People API 的 UpdateContactPhoto 和 deleteContactPhoto、createBatchContact 方法中遇到问题

问题描述

当我使用 UpdateContactPhoto 和 deleteContactPhoto google people API 时出现此错误

获取 updateContactPhoto、deleteContactPhoto 或 createBatchContact => TypeError: service.people.updateContactPhoto is not a function, TypeError: service.people.createBatchContact is not a function, TypeError: service.people.deleteContactPhoto is not a function 的错误。

 API - 
    
        async updateContactPhoto(req, res) {
            try {
               let baseUrl = Buffer.from(req.body.photoUrl, 'utf8').toString('base64');
               let auth = await this.authorize(req, res);
                if (auth.credentials) {
                 
                    let service = google.people({ version: "v1", auth: auth });
                    let data = await service.people.updateContactPhoto({
                        resourceName: req.body.resourceName,
                        requestBody: {
                            "photoBytes": baseUrl,
                        }
                    })
                    console.log("=========>>>   ", data)
                }
            } catch (error) {
                console.log("Error ===>>>>  ", error)
                    }
        }
    
     API -
    
    async createBatchContacts(req, res) {
        try {
            let auth = await this.authorize(req, res);
            if (auth.credentials) {
                const service = await google.people({ version: "v1", auth });
                let batchContact = await service.people.batchCreateContacts({
                    requestBody: {
                        contacts: req.body.contacts,
                        readMask: ["addresses", "emailAddresses", "genders", "interests", "coverPhotos", "locales", "locations", "memberships", "metadata", "miscKeywords", "names", 'nicknames', "occupations", 'organizations', "phoneNumbers", "photos", "relations", 'sipAddresses', 'skills', "urls", "userDefined"],
                    }
                })
                console.log("RESULT  ==>>>> ", batchContact)
            }
        } catch (error) {
            console.log("Error ===>>>>  ", error)
        }
    }

API - 

  async deleteContactPhoto(req, res) {
        try {
               
            let auth = await this.authorize(req, res);
            if (auth.credentials) {
                let service = await google.people({ version: "v1", auth });
           
                let data = await service.people.deleteContactPhoto({
                    resourceName: req.body.resourceName,
                  })
                console.log("=========>>>   ", data)
            }
        } catch (error) {
            console.log("Error ===>>>>  ", error)
          }
    }

创建和更新联系人方法可以在相同的过程中正常工作,但在 updateContactPhoto、deleteContactPhoto 和 createBatchContact API 上出现错误。

标签: google-people-api

解决方案


推荐阅读