Created
June 28, 2011 17:13
-
-
Save gesteves/1051628 to your computer and use it in GitHub Desktop.
Google Apps script to export Google Talk chat logs to a Google Docs spreadsheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Quick instructions: | |
1. Go to Google Docs and open a new spreadsheet. | |
2. Go to Tools > Script editor... | |
3. Delete everything, paste this code in the script editor, and save it. | |
4. Go back to the spreadsheet, Tools > Script manager... | |
5. Select getChats, and press the "run" button. | |
6. It'll ask for a bunch of authorizations. Grant them. | |
7. When it says "now you can run the script", repeat step 5. | |
8. Your chats should being filling the spreadsheet. It'll probably take a while. | |
When it's done, you can save it, and export it as CSV, Excel or whatever. | |
*/ | |
function getChats() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
sheet.getRange(1, 1).setValue("Date"); | |
sheet.getRange(1, 2).setValue("Subject"); | |
sheet.getRange(1, 3).setValue("Body"); | |
var row = 2; | |
var chats = GmailApp.getChatThreads(); | |
var chat_count = chats.length; | |
for (var i = 0; i < chat_count; i++) { | |
var count = chats[i].getMessageCount(); | |
var messages = chats[i].getMessages(); | |
for (var j = 0; j < count; j++) { | |
var chat_date = messages[j].getDate(); | |
var subject = messages[j].getSubject(); | |
var body = messages[j].getBody(); | |
sheet.getRange(row, 1).setValue(chat_date); | |
sheet.getRange(row, 2).setValue(subject); | |
sheet.getRange(row, 3).setValue(body); | |
row++; | |
} | |
} | |
Browser.msgBox("All done!"); | |
} |
I keep running up against "Service invoked too many times: gmail rateMax (line xxx)"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It looks like this might not be possible within a spreadsheet - it's just too slow.
I thought maybe setValue was slowing things down, so I made a version ( https://gist.github.com/1054300 ) that uses setValues instead, but it still ends up timing out.