How to fix Google Calendar API error - node.js

I following https://developers.google.com/google-apps/calendar/quickstart/nodejs#step_3_set_up_the_sample
But it not worked and output below this:
var clientSecret = credentials.installed.client_secret;
^
TypeError: Cannot read property 'client_secret' of undefined
at authorize (/Users/prangyy/myApp/quickstart.js:32:43)
at processClientSecrets (/Users/prangyy/myApp/quickstart.js:21:3)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:404:3)

Change lines 34-36 in quickstart.js to:
var clientSecret = credentials.web.client_secret;
var clientId = credentials.web.client_id;
var redirectUrl = credentials.web.redirect_uris[0];
(There's an error where they've used credentials.installed instead of credentials.web, which is what shows up in the client_secrets.json file.)

Try checking your client_secret.json in the Node.js Quickstart.
It should contain clientID, auth_url, token_uri, auth_provider_x509_cert_url, client_secret, redirect_uris, javascript_origins.
{"web":{"client_id":"YOUR_CLIENT_ID","project_id":"google.com:my-project-1231","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://accounts.google.com/o/oauth2/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"YOUR_CLIENT_SECRET","redirect_uris":["YOUR_REDIRECT"],"javascript_origins":["YOUR_JAVA_ORIGIN"]}}
if not yet, follow this to get your client_secret.json file
Use this wizard to create or select a project in the Google Developers Console and automatically turn on the API. Click Continue, then Go to credentials.
At the top of the page, select the OAuth consent screen tab. Select an Email address, enter a Product name if not already set, and click the Save button.
Select the Credentials tab, click the Create credentials button and select OAuth client ID.
Select the application type Other, enter the name "Google Calendar API Quickstart", and click the Create button.
Click OK to dismiss the resulting dialog.
Click the file_download (Download JSON) button to the right of the client ID.
Move this file to your working directory and rename it client_secret.json.
I hope this helps. Goodluck :)

No need to modify the original code if you check 'Other' (as said in the tutorial) when you choose your Application type in the client ID creation page (step 4 of your pasted text)

Related

Xamarin Forms - Close view after successful login with Azure AD

I'm successfully logging in my Xamarin Forms application with Azure AD.
The problem is that when I'm logged in through the webview opened by default with :
user = await AuthenticationManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, true);
The created webview shows a message telling me that I'm logged in but I don't know how to close this view after that.
Is there an event I can use or am I doing something wrong and the webview is supposed to close itself upon complete authentication ?
EDIT :
I changed my call to :
user = await AuthenticationManager.DefaultManager.CurrentClient.LoginAsync(MobileServiceAuthenticationProvider.WindowsAzureActiveDirectory, false);
Becase I didn't give an SID being a Xamarin Forms project.
The result is that the window closes now but I get and InvalidOperationException with the message :
Invalid format of the authentication response.
Any idea about the format I should give ? I don't see what I could change to be able to get the user connected.
Just leave off the true/false on the end.
For more information on authentication, see chapter 2 of http://aka.ms/zumobook

Netsuite, how to show popup after login into netsuite account?

I am new to Netsuite and I have a requirement to show one alert message displaying "welcomeuser" after the user loggedin into Netsuite account.
I have tried this client script but its not showing any message.
function employee_PageInit(type){
debugger;
alert('Dear UserName, The data in NetSuite is confidential and the property of the company.');
nlapiLogExecution('DEBUG', 'user role', nlapiGetContext().getName());
alert('ok'+ nlapiGetContext().getName());
}
I have logged in with the role ADMINISTRATOR,
any help is appreciated thank you.
Here is a sample with 2.0. It's not pretty and would need some work. But this is one way to inject javascript logic onto the homepage with a portlet.
/**
*#NApiVersion 2.x
*#NScriptType Portlet
*/
define(['N/runtime'],
function(runtime) {
function render(params) {
var user = runtime.getCurrentUser();
params.portlet.title = 'Welcome Message';
var content = '<script>alert(\'Hello ' + user.name + '\');</script>';
params.portlet.html = content;
}
return {
render: render
};
});
U can try using custom portlet it stands out in the dashboard for showing the content.Then also alert is not possible.
I've struggled with this idea in the past and what you want is not technically possible, since there are no scripts that run when you are viewing the homepage. Here are some weird workarounds:
Schedule a calendar reminder, which can trigger a pop-up with your message.
Before assigning their full NetSuite rights, tell users to go to a specific page or form: Maybe a custom record... (the record could serve as a log of who consented to and read your policy) On this form you could have your message. Then when the user fills it out, have a back-end script enable their permissions.
Make your text into a tiny image, and make it your company logo for all of NetSuite. ;)
You can add the custom Javasript to display the alert on a Suitelet which would be set as the Landing Page under General Preferences, then once the user accepts redirect to their home page, and if they don't accept send an alert to the admin...
E.g.
<script>
var accepted = confirm('Dear UserName, The data in NetSuite is confidential and the property of the company.');
if (accepted)
window.open('https://99999.app.netsuite.com/app/center/card.nl?sc=-29&whence=');
else
//Send email to admin
</script>
Hi please follow the following steps :
Create a suitelet script - Login Script with pageInit() in clientscript action to alert your welcome message.
Goto Setup > Company > General Preference and under Centers tab add appropriate URL of the Login Script Suitelet's deployment and save the preferences.
Note : You can add different messages to different center's based on the roles in your account.
General Preference > Centers Tab
Hope this solves your issue please revert back if anything is missed.
Basically, the homepage of NetSuite is not scriptable.
There are some ways to check if the record/page is scriptable:
Look up the specific record type in the NetSuite Help Center; specifically on the Records Browser
On the Browser's developer console, you may run nlapiGetRecordType() and if it returns the record name, it should be scriptable -- please note that the record should be on edit mode for the console tool to run correctly with NetSuite pages
Hope this helps with your development!
you can write a function
function pageInit(type){
var context= nlapiGetContext();
var username = context.getName();
alert(hello+username);
}

How can I get a token for the Drive API?

I want to implement the Google Drive API to my web application using NodeJS and I'm struggling when I try to get a token via OAuth.
I've copied the code from this guide and run the script using Node and it returns an error in this line:
var redirectUrl = credentials.installed.redirect_uris[0];
Googling around I found that I can set that variable as http://localhost:8080 and set the same value in the Authorized redirect URIs configuration in the Google Developers Console and that error goes away, fine, it works. Now it asks for a code that I should get by using an URL.
https://accounts.google.com/o/oauth2/auth?access_type=offline&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fdrive.metadata.readonly&response_type=code&client_id=CLIENT_ID&redirect_uri=http%3A%2F%2Flocalhost%3A8080
Then I've added the client id and enter to that URL with Chrome and then returns a connection refused error. No clue what to do in here, I searched about my problem and I can't found an answer. By looking at the direction bar in Chrome I see that there's a parameter called code and after it, there's random numbers and letters. Like this:
http://localhost:8080/?code=#/r6ntY87F8DAfhsdfadf78F7D765lJu_Vk-5qhc#
If I add any of these values it returns this error...
Error while trying to retrieve access token { [Error: invalid_request] code: 400 }
Any ideas on what should I do? Thanks.
Did you follow all the directions on the page you indicated, including all of those in Step 1 where you create the credentials in the console and download the JSON for it? There are a few things to note about creating those credentials and the JSON that you get from it:
The steps they give are a little different from what I went through. They're essentially correct, but the "Go to credentials" didn't put me on the page that has the "OAuth Consent Screen" and "Credentials" tabs on the top. I had to click on the "Credentials" left navigation for the project first.
Similarly, on the "Credentials" page, my button was labeled "Create Credentials", not "Add Credentials". But it was a blue button on the top of the page either way.
It is very important that you select "OAuth Client ID" and then Application Type of "Other". This will let you create an OAuth token that runs through an application and not through a server.
Take a look at the client_secret.json file it tells you to download. In there, you should see an entry that looks something like "redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"] which is the JSON entry that the line you reported having problems with was looking for.
That "urn:ietf:wg:oauth:2.0:oob" is a magic string that says that you're not going to redirect anywhere as part of the auth stage in your browser, but instead you're going to get back a code on the page that you will enter into the application.
I suspect that the "connection refused" error you're talking about is that you used "http://localhost:8080/" for that value, so it was trying to redirect your browser to an application running on localhost... and I suspect you didn't have anything running there.
The application will prompt you to enter the code, will convert the code into the tokens it needs, and then save the tokens for future use. See the getNewToken() function in the sample code for where and how it does all this.
You need to use this code to exchange for a token. I'm not sure with nodejs how to go about this but in PHP I would post the details to the token exchange url. In javascript you post array would look similar to this ....
var query = {'code': 'the code sent',
'client_id': 'your client id',
'client_secret': 'your client secret',
'redirect_uri': 'your redirect',
'grant_type': 'code' };
Hope this helps
Change redirect uri from http://localhost:8080 to https://localhost:8080.
For this add SSL certificates to your server.

using Cucumber with Netzke to call an action in Grid Panel

I'm working on Rails(3.1.3) with Netzke(0.7.3).
I very new for Cucumber.
add_account_for_user.feature
Feature: Add Account For User Feature
In order to add login account
As an Administrator
I want to add login account for other role
Scenario: Adding Login Account
When I login as an Administrator
Then I should be on admin page
When I click on 'Administration' button at right upper of page
Then I should see 'Administrator Management'
And I should see 'Add' button in Administrator Management toolbar
When I click on 'Add' button
Then I wait 10 seconds # for check what happen
The problem is at When I click on 'Add' button step.
It pass but not working correctly. (It should fire event onAddInForm)
It's hanging in loading and do not show new windows panel.
my_steps.rb
Then /^(?:|I )click on '(\w*)'(?:|.*)$/ do |label|
click_link_or_button(label)
step "wait for the response from sever"
end
When /^(?:|I )wait for (?:.*)$/ do
page.driver.browser.execute_script(<<-JS)
JS
end
Found the solution!!
The solution is try to collect Component that you use. and then call that action directly.
When /I press 'Add' button in the '(\w*)' grid$/ do |grid_name|
page.driver.browser.execute_script <<-JS
var containerComp = Ext.getCmp("main_container");
var grid = containerComp.down("#"+"#{grid_name.underscore}_grid");
grid.onAddInForm();
JS
end
But I still don't understand why it not call onAddInForm after click.

Error in SPUtility send email

I am trying to send an email in the button click event in the webpart.However, the email sending is failed and error is logged in both sharepoint logs and event viewer of the machine.
The error is : Cannot connect to SMTP host
Outgoing email settings in central admin is already configured. Alerts are also working fine.
Below is my code:
StringDictionary headers = new StringDictionary();
headers.Add("to", "someone#abc.com");
headers.Add("from", "MySharePointEmail#myfatblog.co.uk");
headers.Add("subject", "How to use SendEMail from SPUtility");
headers.Add("content-type", "text/html");
string bodyText = "This is the body of my email, in html format.";
SPUtility.SendEmail(SPContext.Current.Web, headers, bodyText);
Thanks in advance
Try running your code without the System Account (if you are).
Try also disabling the LoopbackCheck:
To set the DisableLoopbackCheck registry key, follow these steps:
Click Start, click Run, type regedit, and then click OK.
In Registry Editor, locate and then click the following registry key:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Lsa
Right-click Lsa, point to New, and then click DWORD Value.
Type DisableLoopbackCheck, and then press ENTER.
Right-click DisableLoopbackCheck, and then click Modify.
In the Value data box, type 1, and then click OK.
Quit Registry Editor, and then restart your computer.
I got that fixed. Anti virus was causing the problem. But i am wondering how is SharePoint able to send mail then?

Resources