Connect Google calendar api and api.ai - node.js

So here is what i am trying to do :
I built a bot with api.ai for my business that is hosted on my webpage and my Facebook page right now. Bot works well.
I want to push it to the next step by allowing my customers to make querys on my calendar, ask to book a specific time, see if available, if not offer other time similar, then make a booking.
I have been reading this thread and the great answer attached to it but i think my case is a bit different.
I was wondering if the bot could always have a token so every guests won't have to Auth to query the calendar ?
Obviously i am new to this, i have been reading the guide of google calendar api and api.ai but i don't really see how to do that yet. I guess there is a way to store a token somewhere and then just trigger the query with some specific intents but not to sure how.
I have also done the node.js quickstart guide of the G-calendar api, and it works fine if that helps.
Thanks for your help !

You will probably want to use a Service Account that is permitted to the calendar in question. Service Accounts are similar to regular accounts, but they are expected to do server-to-server communication only, so the method to create an auth token is a little different to keep it secure.
See https://developers.google.com/identity/protocols/OAuth2ServiceAccount for more information about using Service Accounts.
In general, you'll be using a shared secret to create and sign a JSON Web Token (JWT) you send to Google's servers. You'll get back an access token which you'll then use to call the Calendar API. The access token expires in about an hour, at which point you'll need to repeat the process.
There are libraries available to do much of this for you. For example, if you're using the node.js library https://github.com/google/google-api-nodejs-client, then it will take care of this for you (although you need to modify the key file - see the documentation for details).

Related

Which is the correct OAuth Flow for our use case?

First of all, I apologize for eventual noob questions, we are very new to the DocuSign API and are currently trying to wrap our heads around which is the most correct way of accessing the API.
I will start with an overview of our use case. We recently purchased a DocuSign prod. Account with an Organization enabled.
We have a Partner which uses a CMS Tooling which integrates with said DocuSign Account. This Tool allows for the Backoffice to create envelopes with documents inside and a url which leads to the signin ceremony through the Templates that we create inside the DocuSign Account. This url is afterwards send to the customer for them to sign the documents in the envelope. This Part is working and is currently being used.
Now what we want to achieve on our side, we have a nextJS web-app which allows the same customers (Which are the receivers of the created envelopes in the step above, same e-mail in both steps) to sign-in our web-app. We want to show the customer in a dashboard, if there are envelopes for him open that he can sign and if this is the case we want to show him the url which leads to the signin ceremony.
We were able to see that as soon as an envelope for a certain User is created through the CMS Tooling, we can see that envelope in our DocuSign Prod Account.
Now our thought process was, to show our customer his open envelopes, we just fetch all open envelopes in our DocuSign Account which match the customers E-Mail.
Is there anything wrong with this process or are we overlooking something?
And if it is okay to proceed this way which of the OAuth Flows is the correct one to use for this case?
From my understanding, the JWT Flow seems like the most reasonable one? Since the Customers that need to sign the documents, will not have any DocuSign accounts.
What have you tried to solve the issue?
We tried using the direct API Access, which worked when set up correctly but since we didn't have a OAuth Flow in place the Access token is only valid for restricted amount of time obviously and has to be refreshed. Hence we have to think first about how to grant access correctly
I would love to hear, what the right approach would be to achieve our desired result.
Once again Apologies for this kind of question, just trying to have a better understanding before we start building :)
Best regards!
According to the use case you mentioned using JWT Grant is fine as users of your integration will use a single system account to log in, you should use JWT Grant.
I would recommend going with the below link to know more regards different use cases and check the knowledge
https://developers.docusign.com/platform/auth/choose/
https://developers.docusign.com/platform/auth/oauth2-requirements-migration/

Constant Contact V3 API add new contact

I'm attempting to use the new Constant Contact V3 API to add a new email contact. I've been reading the docs: https://v3.developer.constantcontact.com/api_guide/client_flow.html, and trying it out and it seems like the only way to do this now is to make an authentication request, approve the request and then retrieve and access token that is valid for only 2 hours.
I need to have access from my server only and just send an add contact request to Constant Contact. I don't understand why I require to have a redirect uri now and an access token to use the V3 api instead of just using the api key.
With the V2 api I was able to make these types of requests directly from the server without hassle and that's exactly what I need now. The V2 documentation seems to be taken down so I can no longer do that so I'm stuck.
Any help is appreciated.
Based on this link: https://community.constantcontact.com/t5/Developer-Support-ask-questions/v2-or-v3-API-for-very-basic-integration/m-p/324777#M11434, it seems like server-to-server auth is not available still. For those of you who have the same issue, use Mail Chimp or another service that has basic api requirements.
You can get INITIAL Access Token without any code - just use your browser and curl. The Access Token is valid for 24 h, but you can automatically renew it using Refresh Token. You can renew it automatically every time it expires and never need to proceed through INITIAL flow over again. You can read about it here. If you are using C#, I have templates and instructions exactly for your scenario here: https://github.com/mikeks/constantcontact-v3.

How can I get a user's Google account photo using IAP and the People API? (NodeJS preferred)

I have an application that uses Google Cloud IAP to authenticate users. IAP requires the user to authenticate using their Google account, and then headers are passed to the application afterwards that identify that user (user id, user email, and a token).
I would like to get the user's Google account photo after authentication using the People API (would use the Plus api, but it is being shut down).
NodeJS code examples would help a ton, but either a high level guide or examples in other languages would also be very helpful. Thanks in advance!
For anyone that may come across this, here is the solution I found.
You will need to enable the People API in your GCP console. Then create an API key for it.
Get the 'x-goog-authenticated-user-id' header and strip the 'accounts.google.com:' portion of it to just leave the id.
Pass that id and your api key to a GET request, like so:
https://content-people.googleapis.com/v1/people/${userId}?personFields=photos&key=${apiKey}
Hope this helps someone else, too!

Can we use Instagram API for Local Development

I am learning React Native by creating a clone of Instagram (Strictly Local Development). I want to use the Instagram API to get some real time data for my app. I tried registering as Instagram Developer but its asking me for the website and policy page of the website, which I don't have. Is it possible to use Instagram API for learning purpose, if so can you give me the steps for ding it??
Yes, you can. I think you're already in the right way. All you need to do is just integrate things up and follow all the steps in the Instagram Developer website.
You are not required to have policy page or anything to use the sandbox, but you will need it later on if you want to use the API in the production state of your app.
You will need to create an app in the developer site, and generate your access token. Then, add a sandbox user (your Instagram account) and start to use the User Endpoint to retrieve your user data (such as your bio, follower count, etc.) and media (this is what you want, your Instagram post feed).
Hope this helps.

How to access a gmail account I own using Gmail API?

I want to run a node script as a cronjob which uses Gmail's API to poll a gmail account I own.
I am following these quickstart instructions:
I'm stuck on the first step. When requesting credentials for a cron script it tells me that "User data cannot be accessed from a platform without a UI because it requires user interaction for sign-in":
The docs are confusing in general, and mention "service accounts," "OAuth," and other things -- I cannot tell which apply to my use-case and which don't. I've used many SaaS APIs, and the typical workflow is to login to your account, get an API key and secret, and use those in your script to access the API. It seems this is not the paradigm used by the Gmail API, so I'd appreciate any guidance or links to clearer instructions.
I also find that the documentation can be confusing at times, but what you want to to is actually pretty straight forward once you get it:
Register your App at Google, and say what APIs you want your App to have access to (only the Gmail API in this case). This will give you two strings, a client_id and a client_secret (which is the content of the client_secrets.json-file above).
Since you are just going to write a script for your own account only, you don't need a http-server. The Oauth Playground will suffice. Press the Settings Cog on the top right and use your own OAuth credentials.
Select the Gmail API in the list of APIs and follow the outlined steps.
Now you have an access_token and a refresh_token you can use to keep your script going indefinitely!
To fully understand the use of Gmail API, going through Gmail API Overview really will make a difference.
And you can also use these documentations to start building a Gmail app:
The client libraries are available for download in several languages and simplify making API requests.
The developer guide topics help you better understand how to implement particular use cases.
The API reference gives you details on every resource and method in the Gmail API.
I hope these help.

Resources