There are around 15000+ members in my Google Group and I'd like to export them to CSV file. Google Groups says there are too many to export Is there any other way to export all the 15000+ members?
-
Did you find an answer to this question eventually? – Amit Kothari Sep 23 '13 at 14:16
-
it is not possible to export users using any API. I used to create a bookmarklet to fetch the emails from the page using Javascrip. – Punithavel Oct 21 '13 at 12:04
-
So you were only interested in scraping the email addresses? – Mike B Oct 22 '13 at 11:22
2 Answers
This is possible using the Directory API. You can see how to set up a project in the Google Developer's Console with the appropriate scopes here. I have a sample of code below that shows how I did this for my email list manager (written in Python3). Note that mine just outputs to a list, but you could write to a csv as well.
import urllib.request, urllib.parse, urllib.error
import json
req = urllib.request.Request("https://www.googleapis.com/admin/directory/v1/groups/%s/members" % (group.replace("@", "%40").replace(".", "%2E")))
req.add_header("Authorization", "Bearer %s" % (authToken))
rawResponse = urllib.request.urlopen(req)
fResponse = json.loads(rawResponse.readall().decode('utf-8'))
if "members" in fResponse:
curMembers = fResponse["members"]
while "nextPageToken" in fResponse:
req = urllib.request.Request("https://www.googleapis.com/admin/directory/v1/groups/%s/members?pageToken=%s" % (group.replace("@", "%40").replace(".", "%2E"), fResponse['nextPageToken']))
req.add_header("Authorization", "Bearer %s" % (authToken))
rawResponse = urllib.request.urlopen(req)
fResponse = json.loads(rawResponse.readall().decode('utf-8'))
if "members" in fResponse:
curMembers.extend(fResponse["members"])
You'll need to define a way to retrieve the oauth2 authentication token (authToken in the above snippet). I do so as below, but there are dedicated libraries for this (just not for Python3 that I know of):
def RenewToken():
"""
This function retrieves an authentication token from Google which will allow the script
to view and edit group membership
"""
clientID = "client_id.apps.googleusercontent.com"
clientSecret = "client_secret"
grantType = "refresh_token"
responseType = "code"
refreshToken = "refresh_token"
requestDict = {"client_secret": clientSecret, #field-value pairs for the request body
"grant_type": grantType,
"refresh_token": refreshToken,
"client_id": clientID}
requestUri = "https://accounts.google.com/o/oauth2/token"
requestString = urllib.parse.urlencode(requestDict)
requestBody = requestString.encode('utf-8')
request = urllib.request.Request(requestUri, data=requestBody)
response = urllib.request.urlopen(request)
responseDict = json.loads(response.readall().decode('utf-8'))
return responseDict['access_token']
You can get client_id, client_secret and refresh_token from the Google developer's console for your project.

- 21
- 5
you can export all contacts in your google group in a Google Spreadsheet
link : https://developers.google.com/apps-script/reference/groups/
After you can create a trigger to add new contact dynamically, and export you Google spreadsheet on a cvs's file.
you can create this solution quickly and simple.

- 727
- 3
- 11
- 22