Getting Notification from facebook friends who accepted my invitation request - actionscript-3

private function InviteMyFriends(e:MouseEvent):void{
var dat:Object = new Object();
dat.message = "Let's invite friends for our Super Krish QuizGame Facebook App to get bonus points";
dat.title = 'Super Krish QuizGame Facebook App';
// filtering for non app users only
dat.filters = ['app_non_users'];
//You can use these two options for diasplaying friends invitation window 'iframe' 'popup'
Facebook.ui('apprequests', dat, onUICallback, 'popup');
}
private function onUICallback(dat):void{
var result:Object = dat;
if(result == null){
mtline.trace2_txt.text = "User closed the pop up window without inviting any friends";
return
}
var invitedUsers:Array = new Array();
invitedUsers = result.request_ids as Array;
mtline.trace2_txt.text ="You Have Invited " + invitedUsers.length+ " friends";
//Simple if else if you want user to invite certain amount of friends
if(invitedUsers.length > 1){
mtline.trace2_txt.text = "GREAT, USER IS GENERATING TRAFFIC";
}else{
mtline.trace2_txt.text = "No Good, User invited only one friend ";
}
}
Hi,here i have used this code to send my facebook game invitation to my friends using facebook api with action scripting.its working perfectly but i need to identify my friends who accepted my invitation because i have to provide 500 points to the user who send the invitation to his friends after the invitation gets accepted.Kindly help regarding this.
Thanks in advance

That workflow you're proposing is explicitly against Facebook policy and your app could lose the ability to send requests as a result, just be aware of that before you proceed any further.
As for how to track accepted requests, you already have to read and delete the requests when the user clicks 'accept' on them, so you should log at send-time the request IDs and update your records when you're processing the accepted requests

Related

noReply mail with apps script should ignore already replied mailadresses

whats up :D
I hav set up a very, very eased up noreply mailresponder.
UseCase:
We send some kind of notification via Email from our service (Like: "Hey, check out new message")
But the receiver of that mailnotification should not respond to our email notification.
If he still does we have set up an email auto responder ->
curently what i have done with apps scripts on google is following:
function AutoResponder() {
var query = "is:unread" ;
var unread = GmailApp.search(query);
for (var i in unread)
{
var thread = unread[i];
var messages = thread.getMessages();
if (messages.length === 1) { // the reply
body =
"<p> Blabla dont reply to our email thx </p>"
options =
{
name: "This is the subject of mail",
htmlBody: body
};
thread.reply("", options);
}
}
}
Ive set a trigger like every 15 mins the code will get excecuted.
Works quite well but i have an issue:
When recipient has set an autoresponder aswell, they keep looping (sending each other this autoresponder mail) until i delete the last email of that user, so script wont be able to see that thread in the google message list screen.
But i would like to implement that in the code, somehow try to cache the sendermail and not send an response for few hours.
Is that somehow possible?
Thank you guys in advance and have a nice week guys!!

Does the following google script exactly delete the messages with certain label?

My goal is to make sure that all incoming Gmail messages from test#test.com are immediately permanently deleted.
I have created a filter that gives new messages from this address the label "deleteforever". Next, I have made a Google script that completely deletes all messages with the label "deleteforever". To be certain that no other messages are deleted, I check an extra time whether the messages really are from test#test.com. In this way, when a thread contains messages from test#test.com and messages from another address, only the messages from test#test.com should be deleted.
I plan to run it every minute. I have 3 questions:
Does this algorithm always completely delete all new messages from test#test.com?
Does this algorithm never delete a message from another sender?
Will this not cost too much runtime, assuming that test#test.com does not send many emails? (I saw that there is a limit of 1 hour per day.)
function extractEmailAddress(header) {
return header.match(/[^#<\s]+#[^#\s>]+/)[0];
}
function deleteForever() {
var threads, msgs, label1, label2, sender,message,messageId;
label1="test#test.com";
label2="Test#test.com";
threads= GmailApp.getUserLabelByName("deleteforever").getThreads();
msgs = GmailApp.getMessagesForThreads(threads);
for (var i = 0 ; i < msgs.length; i++) {
for (var j = 0; j < msgs[i].length; j++) {
message=msgs[i][j];
sender = extractEmailAddress(message.getFrom());
if (sender==label1 || sender==label2){
messageId=message.getId();
Gmail.Users.Messages.remove("me", messageId);
}
}
}
}
UPDATE
Inspired by the comment of #TheMaster, the following strategy solves the potential runtime problem:
-modify the filter in Gmail so that messages from test#test.com skip the inbox.
-hide the "deleteforever" folder
Now the script can be run every 5 minutes or with even lower frequency.
Since you are open to muting the notifications as suggested by TheMaster and running the script/function on a less frequent basis, I suggest you improve it further by using Gmail API, specifically batchDelete to improve the performance.
Script:
function deleteForever() {
label_name = 'deleteforever';
sender1 = 'do-not-reply#stackoverflow.email';
sender2 = 'forms-receipts-noreply#google.com';
// get labelId of label_name
var labelId = Gmail.Users.Labels.list("me").labels.filter(label => label.name == label_name)[0].id;
// filter messages where it has labelId and from either sender1 or sender2
var messages = Gmail.Users.Messages.list("me", {
"labelIds": labelId,
"q": `{from: ${sender1} from: ${sender2}}`
}).messages;
// if messages is not empty
if(messages){
// get ids of the messages
var ids = messages.map(message => message.id);
// bulk delete the messages
Gmail.Users.Messages.batchDelete({"ids": ids}, "me");
}
}
This will delete the accumulated message IDs by bulk where it meets the conditions:
Sender is either sender1 or sender2
Has label label_name.
Note:
You will not need extractEmailAddress anymore.

How to get Google calendar events shared by another owner?

I am new to the calendar api and have a couple of basic questions.
I want to get all of the events, on all of the calendars, that another user, tonya123456#gmail.com has shared with me. She is the owner, not me.
"This user owns or is subscribed to 0.0 calendars" is the response when I run this code:
var calendar = CalendarApp.getCalendarsByName('tonya123456#gmail.com');
if(calendar == null){
//user may not have access, auto-subscribe them.
calendar = CalendarApp.subscribeToCalendar('tonya123456#gmail.com',
{hidden:true,selected:false});
}
Logger.log('This user owns or is subscribed to %s calendars.',
calendar.length);
One way I know of is listing all your own events that has a creator that you are looking for. The function below will grab your events and return an array of event ids that match the event creator. This isn't an inclusive solution, such as it doesn't have date ranges or handle paginated results and is just one simple way to approach this.
https://developers.google.com/google-apps/calendar/v3/reference/events/list
function getEventIdsByCreator(calendarId,creator){
return Calendar.Events.list(calendarId,{fields:"items/id,items/creator/email"})
.items.filter(function(item){
try{if(item.creator.email === creator){return true}}
catch(e){}
}).map(function(item){return item.id});
}
You would use it like:
function myFunction(){
var IDs = getEventIdsByCreator(myCalendarId,"tonya123456#gmail.com")
}

Is there a way to create a script for google form to check a spreadsheet first?

I am trying to plan my sons 1st birthday party. I live in hawaii so when you invite someone, sometimes they tend to bring their friends, sisters, cousins, auntys, uncles, dog, etc..... but since the venue we reserved for my sons party has a limited amount of seating, we can't just have additional people come. Plus we are paying by the head/seat.
So with that said, I have a spreadsheet of my guest list and have a column for the amount of seats I have limited to each invitation. I would like to assign a code for each invitation as well.
For example
Family Name | Seats | Code Number
Family A | 3 seats | ABC123
Family B | 5 seats | DEF456
So if I place a qr code on the invitation and give each invitation/family their code,
I would like google forms to allow each recipient to enter their code and for a script to check my spreadsheet with this code they entered so the form knows how many seats the recipient is limited to reserving for.
Family A can only reserve for 3 seats and no more, and Family B can only reserve for 5 seats and no more.
Is there a way to do this?
You can't enter a code into a Google Form field and have a script function run right after. So that kills being able to check on the validation of another field. Only after the Form has been submitted to go the the responses can you check what the values were.
If you stick with a single Google form you could write a script that monitors submissions and sends out an email or letting them know they booked too many people (after the fact). Could also write a script that creates a separate Form for each invite that already has the maximum guests programmed into a drop down list. Then send each invite their own Form url.
Another way is to write your own app with one of the 2 UI Services that acts like a form. There you can have interaction with user input and the validation you want. Start of a UiApp example...
var MAX = [];
MAX['123'] = [2];
MAX['456'] = [3];
function doGet() {
var app = UiApp.createApplication();
var panel = app.createVerticalPanel();
var code = app.createTextBox().setId('code').setName('code');
var guests = app.createTextBox().setId('guests').setName('guests');
var submit = app.createButton('SUBMIT').setId('submit').setEnabled(false);
var status = app.createLabel('', false).setId('status');
var handler = app.createServerHandler('checkGuests').addCallbackElement(panel);
guests.addValueChangeHandler(handler);
handler = app.createServerHandler('submit').addCallbackElement(panel);
submit.addClickHandler(handler);
panel.add(code).add(guests).add(submit).add(status);
app.add(panel);
return app;
}
function checkGuests(e) {
var app = UiApp.getActiveApplication();
var code = e.parameter.code;
var guests = e.parameter.guests;
if (code == '' || code == undefined) {
app.getElementById('submit').setEnabled(false)
app.getElementById('status').setText('Please enter your code.'); }
else if (parseInt(guests) <= MAX[code]) {
app.getElementById('submit').setEnabled(true);
app.getElementById('status').setText(''); }
else {
app.getElementById('submit').setEnabled(false)
app.getElementById('status').setText('Whoops, too many people!'); }
return app;
}
function submit(e) {
}

How to add the contact using EWS

I have 2 questions
I want to add the email Contact to Exchange server.I have seen the sample code using EWS.But that code used to add the contact for user specific.How to add the contact domain specific.
I want to get the domain contacts from Exchange server.I dont want all the contact i need only the today's added or modified contacts.
How can i acheive this .Can any one help me?
Regards
Vairamuthu.G.S
I did not understand "contact domain specific" but I will share you my code. It may help
Adding contact
ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
// you should set the credentials of the user and
//call AutoDiscover to get the service URL before executing the code
Contact newcontact = new Contact(service);
newcontact.DisplayName = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1] = new EmailAddress();
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Address = "data";
newcontact.EmailAddresses[EmailAddressKey.EmailAddress1].Name = newcontact.DisplayName;
newcontact.FileAs = newcontact.DisplayName;
newcontact.Save();
Note that the new contact is saved in the contacts folder in the mailbox of the logging in user.
Filtering the retrieved contacts
SearchFilter filter = new SearchFilter.IsGreaterThan(ItemSchema.DateTimeCreated, DateTime.Now.AddDays(-1));
FindItemsResults<Item> contactCreatedToday = service.FindItems(WellKnownFolderName.Contacts, filter, new ItemView(int.MaxValue));
foreach (Item t in contactCreatedToday)
{
try
{
Contact c = (Contact) t;
//do processing
}
catch (InvalidCastException)
{
throw;
}
}