I have a Google Apps Script that executes as me.
In the script, I want to know the user's email.
So I refer to the email of the user accessing my application as Session.getActiveUser().getEmail()
That's not working out at all. Google Apps Script is giving an error, saying
Session.getActiveUser().getEmail() is NULL.
When I manually enter a dummy email instead of Session.getActiveUser().getEmail(), the code works perfectly
PS: The app MUST execute as me, because it needs to access my contacts.
You cannot have Session.getActiveUser().getEmail() return the user's email id while the app is running as you. There are some workarounds you can try
Ask for the user's email id explicitly.
Write two scripts - one which is the front end UI etc. that run as the user accessing the app (this allows Session.getActiveUser().getEmail() to return the user's email address). Have a second script that does the tasks where your contacts are accessed.
Call the second script from the first by using doPost and doGet methods in your second script.
For example,
Script 1:
function whatever(){
UrlFetchApp.fetch('SERVICE_URL_OF_SCRIPT_2');
}
Script 2:
function doGet(e){
// code to access your contact, get parameters in e.parameters
}
Related
Hi I am working on a web2py project.
I use auth object to create login feature
And using the following code
auth.settings.extra_fields['auth_user']= [Field('address')]
So whenever, an user sign up for an account, the person need to put address.
What I would like to do is display the address in default/index.html when the user login to my application.(the user can view his own address only, not the others)
Do I need to deal with db.auth_user??
I have no clue...
Can you help me?
Thank you.
If the user is logged in, the entire user record is available in auth.user (which will have a value of None if the user is not logged in). So, to display the address in a view:
{{=auth.user.address}}
You could also retrieve the user record from the database via db.auth_user(id) or db(db.auth_user.id == id).select().first(), but using auth.user is more efficient, as it is stored in the session and therefore does not require a database query.
So I am writing some E2E tests for creating an account on a website. After creating a website account, the website will send me an email to verify my account so I can login. My question is, how far is E2E testing suppose to go? would I be going in the wrong direction if I use protractor to go to google, find the email, and click the link to verify myself. Then go back to the website and login? My other possible option would be to somehow get my userID and then send a request for verification?
I'm just not sure which direction would be best. Any ideas?
It is pretty much arguable how far your tests should go. But if there is a critical to testing information being sent on email, you should consider extracting that information during the test run.
In other words, this is so called "end-to-end testing", but both of the ends could be beyond the borders we are used to think and consider.
Here is the solution using mail-listener2 nodejs library that worked for me during the Two Factor Authentication functionality test (registration code is sent to an email after passing username/password verification step).
Personally I do test that a verification email gets sent with the correct contents — I do not, however, login at Google, to find the email. Instead I've exposed a server side function that returns the latest email it sent to a certain email address. Here's how I use it:
b.get(origin + '/-/e2e/last-email-sent?to=' + address, (response) => {
var responseObj = JSON.parse(response.body);
// Now I have the email text in responseObj.bodyHtmlText.
// Let's extract the URL to the next page:
// (it's the first thing we find that starts with our server origin, i.e.
// http://whatever/....)
var regexString = originRegexEscaped + '\\/[^"]+';
var matches = responseObj.bodyHtmlText.match(new RegExp(regexString));
if (!matches) {
b.assert.fail(responseObj.bodyHtmlText, regexString,
'No next-page-link regex match in email');
}
else {
// Tell our e2e browser to go to the page linked in the email
// as if the user had clicked the link in the email.
b.url(matches[0]);
}
});
I'm going to add lots of other funny e2e test server side functions too, like /-/e2e/fast-forward-time?how-much=3600-seconds :-)
What I do test, with a real Gmail user (a real Gmail account I created for e2e tests and nothing else), is just signups. I.e. that OpenAuth login works. If that works, I'm going to assume any Gmail user is thereafter able to read emails.
I am new in CloudKit and just now analyzing CloudKitAtlas from Developer Library.
I create app where i want to "share" data to another user of the same app.
I have CKContainer in private database, where user put all his created dictionaries. Now i want to give him possibility to share some part of his data to another user (create public containerWithIdentifier) . I know is possible to check every email address from address book and get result who have that app installed. So user can choose who will be able to see his data.
The question is how to tell another user app "look to that CKContainer on my shared data" :)
Anyone already do something like this?
You can list all users from your addresbook that has the app installed using the container discoverAllContactUserInfosWithCompletionHandler method. It will return an array from which you can get an recordID. If you want to share something with one of those users, then create a record where you put that ID in a to field. On startup of your app you will have created a subscription with a predicate that looks for that TO field and compare that to your own user recordId. So if a record is created with your ID in the TO field, then you will receive a notification. Whatever you want to send to an other user must be in the public database. I am working on something like this. The code can be found at https://github.com/evermeer/EVCloudKitDao (work in progress)
Check the CKContainer.h in CloudKit framework, they discover people in your contacts by their email address. If that email address in contacts is not the email address to login apple id (or icloud account?), I guess it can not match.
typedef NS_OPTIONS(NSUInteger, CKApplicationPermissions) {
/* Allows the user's record in CloudKit to be discoverable via the user's email address */
CKApplicationPermissionUserDiscoverability = 1 << 0,
} NS_AVAILABLE(10_10, 8_0);
I am developing an application page in sharepoint 2010, in this page the users gets a list of available training courses, and there is a link to register to it.
The problem is that the common users does not have access to the list where the attendances are register, so if I run the application with an user with priviledges it works, but if I try to run it with a common user it fails.
What can i do?
Thanks for any advice ..!
Your code block must run by the following code:
SPSecurity.RunWithElevatedPrivileges(delegate() {
// write to list code ...
}
I am quite new in Facebook application development. I was playing the all day with "how to post a message on the wall of a page?". I finally succeeded but each message got "via Graph API Explorer". I tried to find how to change it to my application name without success. I tried to see if I could force the value of application in the api command but it did not take it into account. Maybe I miss something :( If someone can help, that would be great!
I am still quite confused. Let me try to explain what I want to do: I would like to automatically publish on a page (as the page) some event that are defined on a website (in a kind of agenda). What I miss, I think, is how everything is working together on Facebook side:
1. the login process: as the application will run in a cron, this should not display a login dialog box.
2. the access token: application or page one?
3. the permissions: from my understanding, I need manage_pages (and publish_stream) but not clear how this should be set.
Thx for any clarification and maybe a clear example :o)
You need the user to authorise your own App using one of the Login flows and grant you one of the publishing Permissions -
If it says 'via Graph API Explorer' on the posts your app makes you're using the access token you retrieved when you were testing the API using the Graph API Explorer tool, not one produced by your own app
OK I think I have finally found the way to do it. I needed a page access code and not an application access code. The token must be generated outside the application as a long live one.
Get a code using:
https://www.facebook.com/dialog/oauth?client_id={app_id}&redirect_uri={my_url}&scope=manage_pages,publish_stream
app_id is your application ID
my_url is your application URL
scope is the permission you want to be granted
In the redirected URL, you will have a code parameter. Copy it.
Generate the user access code using:
https://graph.facebook.com/oauth/access_token?client_id={app_id}&redirect_uri={my_url}&client_secret={app_secret}&code={code}
app_secret is your application secret key
code is the code from step 1
You will get as output the user access token. This one is a short live one.
convert the short live to a long live user access token using:
https://graph.facebook.com/oauth/access_token?grant_type=fb_exchange_token&client_id={app_id}&client_secret={app_secret}&fb_exchange_token={short live access token}
Replace the "short live access token" by the one you got on step 2
You will get as output the infinite user access token.
Get the page access token (this one will be infinite access token as
the user access token is now an infinite access token too):
https://graph.facebook.com/me/accounts?access_token={infinite user access token}
Replace the "infinite user access token" with the value you got on step 3.
This command will list all the pages you administer. The output contains the page access token you need in field "access_token". You can so use this token in any API command in your application.
The best of the best is to do all those steps via a server side program (PHP for me) as the application secret key should remain "secret".