How to get more than 30 contacts using Google People API method people.searchContacts

Viewed 84

Heading

A short description of the issue:

We want to use google contacts based on searched for querying domain-name.

so for that we are using Google's people.searchContacts Method from people api to get those contacts with search.

That method is working perfectly fine as its gives us the proper searched contacts based on the domain we are passing.

But we have one issue like as per Google's people.searchContacts method documentation default we are getting 10 contacts and for pageSize we can pass maximum 30.

What is the solution if we need more than 30 contacts by using method people.searchContacts ?

A small code sample that reliably reproduces the issue.

public async init(token?): Promise<any> {
    return new Promise((resolve, reject) => {
        const clientObj = gapi.client.init({
            apiKey: this.googleApiKey,
            clientId: this.googleClientKey,
            discoveryDocs: this.DISCOVERY_DOCS,
            scope: this.SCOPES,
            prompt: 'select_account'
        }).then(async () => {
            try {
                // Listen for sign-in state changes.
                await gapi.auth2.getAuthInstance().isSignedIn.listen(this.updateSigninStatus);

                if (!gapi.auth2.getAuthInstance().isSignedIn.get()) {
                    await gapi.auth2.getAuthInstance().signIn();
                }
                this.updateSigninStatus(token, gapi.auth2.getAuthInstance().isSignedIn.get()).then(async (result) => {
                    const handleState = [{ 'handleState': result ? [...result.connections] : [] }, { currentUser: await 
                                                            gapi.auth2.getAuthInstance().currentUser.get() }];
                    const nextPageToken = result.nextPageToken;
                    resolve({handleState, nextPageToken});
                },
                    (err) => {
                        reject(err);
                    })
            } catch (err) {
                if (err) {
                    reject(err);
                }
            }
        }, function (error) {
            if (error) {
                reject(error);
            }
        });
    })
}

/**
 *  Sign in the user upon button click.
 */
public async handleAuthClick(): Promise<any> {
    await gapi.auth2.getAuthInstance().signIn();
}

/**
 *  Sign out the user upon button click.
 */
public async handleSignoutClick(): Promise<any> {
    await gapi.auth2.getAuthInstance().signOut();
}

/**
 *  Called when the signed in status changes, to update the UI
 *  appropriately. After a sign-in, the API is called.
 */
public async updateSigninStatus(token, isSignedIn): Promise<any> {
    return new Promise(async (resolve, reject) => {
        if (isSignedIn) {
            try {
                const result = await this.listConnectionNames(token);
                resolve(result);
            } catch (error) {
                /** Not handled case and not required */
                // console.log("error", error);
                reject(error)
            }
        } else {
            console.log("Nothing to update");
        }
    });
}

/**
 * Print the display name if available
 */
public async listConnectionNames(token): Promise<any> {
    return new Promise((resolve, reject) => {
        gapi.client.people.people.searchContacts({
            'readMask': 'names,emailAddresses,phoneNumbers',
            'pageSize': 30,
            'query': 'sharklasers.com',
        }).then(function (response) {
            const connections = response.result.results;
            const nextPageToken = response.result.nextPageToken;
            resolve({connections, nextPageToken});
        }, (err) => {
            reject(err);
            let result = confirm("You have not selected the checkbox.");
            gapi.auth2.getAuthInstance().signIn().then(res => {
                if (result) {
                    alert("Refreshing the page...")
                    window.location.reload();
                }
            },
                (err) => {
                    reject(err);
                })
        });
    });
}

What steps will reproduce the problem?

  1. First we are calling below mentioned API
  2. with this parameters readMask, pageSize, query for people.searchContacts
  3. then we are getting proper output with only 30 contacts

What is the expected output?

  • We require more than 30 contacts by using google people API method people.searchContacts
0 Answers
Related