I am building a meteor application.In many instances i need to access google service such as sharing,uploading files etc.
Gone through Google's guide, but some area is not clear.
Created a new project,then in overview enabled drive API.
Created Credentials-->Service Account Key--->App Engine.
Downloaded the private key.
And in my application there is a button when clicked it should access the google services such as if the button is intended for file sharing then it should access google's share service or if it is intended for file uploading then it should access google's upload to drive service and similarly I want to view the files uploaded to google drive in my application.
Somebody help me with the code since I am very new to meteor and this I am finding difficulty in developing
You can follow the quickstart Google provided. Use it as a stepping stone to familiarize yourself on the behavior, errors, best practices in using the api.
Here is the sample code for listing the file names and IDs:
/**
* Lists the names and IDs of up to 10 files.
*
* #param {google.auth.OAuth2} auth An authorized OAuth2 client.
*/
function listFiles(auth) {
var service = google.drive('v3');
service.files.list({
auth: auth,
pageSize: 10,
fields: "nextPageToken, files(id, name)"
}, function(err, response) {
if (err) {
console.log('The API returned an error: ' + err);
return;
}
var files = response.files;
if (files.length == 0) {
console.log('No files found.');
} else {
console.log('Files:');
for (var i = 0; i < files.length; i++) {
var file = files[i];
console.log('%s (%s)', file.name, file.id);
}
}
});
}
NOTE: Follow the prerequisite.
Enable the Drive Platform
Authorizing Your App with Google Drive
Further Readings that will help you with google integration
Google Developers Console help documentation
Google APIs Client for Node.js documentation
Drive REST API reference documentation
Tutorials
Here is a tutorial for implementation of Google OAuth 2.0 for server-to-server interactions for Meteor. You can also using JavaScript application that makes requests to the Drive API.
Related
Manifest version 3 for Chrome extensions have been killing me lately. Been able to navigate around it so far, but this one has really stumped me. I'm trying to use Firebase authentication for a Chrome extension, specifically with 3rd party auth providers such as Google and Facebook. I've setup the Firebase configuration for Login with Google and created a login section in the options page of the Chrome extension and setup the Firebase SDK.
Now, there are two login options when using an auth provider, signInWithRedirect and signInWithPopup. I've tried both of these and both have failed for different reasons. signInWithRedirect seems like a complete dead end as it redirects to the auth provider, and when it attempts to redirect back to the chrome-extension://.../options.html page, it just redirects to "about:blank#blocked" instead.
When attempting to use signInWithPopup, I instead get
Refused to load the script 'https://apis.google.com/js/api.js?onload=__iframefcb776751' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
In v2, you could simply add https://apis.google.com to the content_security_policy in the manifest. But in v3, the docs say
"In addition, MV3 disallows certain CSP modifications for extension_pages that were permitted in MV2. The script-src, object-src, and worker-src directives may only have the following values:"
self
none
Any localhost source, (http://localhost, http://127.0.0.1, or any port on those domains)
So is there seriously no way for a Google Chrome extension to authenticate with a Google auth provider through Google's Firebase? The only workaround I can think of is to create some hosted site that does the authentication, have the Chrome extension inject a content script, and have the hosted site pass the auth details back to the Chrome extension through an event or something. Seems like a huge hack though and possibly subject to security flaws. Anyone else have ideas??
Although it was mentioned in the comments that this works with the Google auth provider using chrome.identity sadly there was no code example so I had to figure out myself how to do it.
Here is how I did it following this tutorial:
(It also mentions a solution for non-Google auth providers that I didn't try)
Identity Permission
First you need permission to use the chrome identity API. You get it by adding this to your manifest.json:
{
...
"permissions": [
"identity"
],
...
}
Consistent Application ID
You need your application ID consistent during development to use the OAuth process. To accomplish that, you need to copy the key in an installed version of your manifest.json.
To get a suitable key value, first install your extension from a .crx file (you may need to upload your extension or package it manually). Then, in your user data directory (on macOS it is ~/Library/Application\ Support/Google/Chrome), look in the file Default/Extensions/EXTENSION_ID/EXTENSION_VERSION/manifest.json. You will see the key value filled in there.
{
...
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAgFbIrnF3oWbqomZh8CHzkTE9MxD/4tVmCTJ3JYSzYhtVnX7tVAbXZRRPuYLavIFaS15tojlRNRhfOdvyTXew+RaSJjOIzdo30byBU3C4mJAtRtSjb+U9fAsJxStVpXvdQrYNNFCCx/85T6oJX3qDsYexFCs/9doGqzhCc5RvN+W4jbQlfz7n+TiT8TtPBKrQWGLYjbEdNpPnvnorJBMys/yob82cglpqbWI36sTSGwQxjgQbp3b4mnQ2R0gzOcY41cMOw8JqSl6aXdYfHBTLxCy+gz9RCQYNUhDewxE1DeoEgAh21956oKJ8Sn7FacyMyNcnWvNhlMzPtr/0RUK7nQIDAQAB",
...
}
Copy this line to your source manifest.json.
Register your Extension with Google Cloud APIs
You need to register your app in the Google APIs Console to get the client ID:
Search for the API you what to use and make sure it is activated in your project. In my case Cloud Firestore API.
Go to the API Access navigation menu item and click on the Create an OAuth 2.0 client ID... blue button.
Select Chrome Application and enter your application ID (same ID displayed in the extensions management page).
Put this client ID in your manifest.json. You only need the userinfo.email scope.
{
...
"oauth2": {
"client_id": "171239695530-3mbapmkhai2m0qjb2jgjp097c7jmmhc3.apps.googleusercontent.com",
"scopes": [
"https://www.googleapis.com/auth/userinfo.email"
]
}
...
}
Get and Use the Google Auth Token
chrome.identity.getAuthToken({ 'interactive': true }, function(token) {
// console.log("token: " + token);
let credential = firebase.auth.GoogleAuthProvider.credential(null, token);
firebase.auth().signInWithCredential(credential)
.then((result) => {
// console.log("Login successful!");
DoWhatYouWantWithTheUserObject(result.user);
})
.catch((error) => {
console.error(error);
});
});
Have fun with your Firebase Service...
I would like to use IBM Watson Conversation service to build a chatbot web application in the Asp.Net platform. I installed IBM.WatsonDeveloperCloud Asp.Net package today, but have no idea what I should do with it and there is no document. There are about 50 projects in the solution, which one can be used for the so called simple chatbot web application?
Watson Developer Cloud has all the documentation that you need to use Watson Services, include Conversation Service.
Here are some examples to use Conversation:
Installation
Nuget
PM > Install-Package IBM.WatsonDeveloperCloud.Conversation.v1
Project.json
"dependencies": {
"IBM.WatsonDeveloperCloud.Conversation.v1": "1.2.0"
}
Usage
You complete these steps to implement your application: Configure a workspace. With the easy-to-use graphical environment, you set up the dialog flow and training data for your application. Develop your application. You code your application to connect to the Conversation workspace through API calls.
Instantiating and authenticating the service
Before you can send requests to the service it must be instantiated and credentials must be set.
// create a Conversation Service instance
ConversationService _conversation = new ConversationService();
// set the credentials
_conversation.SetCredential(<username>, <password>);
Send message:
// create message request
MessageRequest messageRequest0 = new MessageRequest()
{
Input = new InputData()
{
Text = <input-string0>
}
};
// send a message to the conversation instance
var result0 = _conversation.Message(<workspace-id>, messageRequest0);
// reference the message context to continue a conversation
messageRequest messageRequest1 = new MessageRequest()
{
Input = new InputData()
{
Text = <input-string1>
},
Context = result.Context
};
// Send another message including message context.
result1 = _conversation.Message(<workspace-id>, messageRequest1);
Obs.: In this link have one full guide step-by-step to use Watson Conversation Service with .Net.
See the Official Documentation for .Net SDK
One good Tutorial Video Guide to Integrating Watson Conversation in your Application.
See the Official API Reference for use Watson Conversation Service (You can have a base with this link).
I recently read Taiseer’s post on “ASP.NET Web API 2 external logins with Facebook and Google in AngularJS app”. I got my solution working perfectly with Google and Facebook. I decided to extend the project to support Vk.
Does anyone know how I can obtain the user id and app id like the Google implementation. In the code below I’m trying to call a similar call like the one for Google and retrieve the user id and app id.?
else if (provider == "Google")
{
verifyTokenEndPoint = string.Format(#"https://www.googleapis.com/oauth2/v1/tokeninfo?
access_token={0}", accessToken);
}
else if (provider == "Vkontakte")
{
verifyTokenEndPoint = string.Format(#"https://oauth.vk.com/access_token?
client_id={0}&client_secret={1}&code={2}&redirect_uri=http://localhost:26264/signin-vkontakte");
}
I have been using the Google api client to access my companies' analytics data for the last 3 months using the method below, and it worked fine.
I then had to repeat the process with a different analytics account and I cannot get anything other than { "error" : "unauthorized_client", "error_description" : "Unauthorized client or scope in request." }
The account is set up on console.developers.google.com under the account I want to impersonate, and the details/.p12 key are copied correctly.
I am not on a google apps domain, so no delegation is needed. I cannot understand why one service account/impersonation works fine, but I cannot recreate for any other analytics account.
Here is what I am using:
function __construct ()
{
parent::__construct();
// accessed via google developer console
$client_email = '****.gserviceaccount.com';
$private_key = file_get_contents(__DIR__ .'/cm-suite.p12');
$scopes = array(\Google_Service_Analytics::ANALYTICS_READONLY);
$user_to_impersonate = '****EMAIL***';
$credentials = new \Google_Auth_AssertionCredentials(
$client_email,
$scopes,
$private_key,
'notasecret',
'http://oauth.net/grant_type/jwt/1.0/bearer',
$user_to_impersonate
);
$client = new \Google_Client();
$client->setAssertionCredentials($credentials);
if ($client->getAuth()->isAccessTokenExpired())
$client->getAuth()->refreshTokenWithAssertion();
// set reference for instance methods
$this->client = &$client;
}
The accounts are added correctly in Analytics, and all the secure details are correct (if I am not trying to use a sub account, the service account connects correctly).
This problem is programming language agnostic I believe as my example worked before using a different account - so must be a configuration issue, or something I have missed settings-wise.
I cannot understand why it works for one google account, and not another.
I use google scripts to fill Google Spreadsheet by Google Analytics data.
Problem: I get error: Login Required when I call =getCountOfNewUsers(B1,B2) from my Spreadsheet file. NOTE: when I run runTest() from google script project everything working OK.
FYI: I have followed this tutorial.
function runTest() {
try {
var results = getCountOfNewUsers(new Date(), new Date());
Logger.log(results.totalsForAllResults["ga:newVisits"]);
} catch(error) {
Logger.log(error.message);
}
}
function getCountOfNewUsers(date_from, date_till) {
date_from = Utilities.formatDate(date_from, 'GMT', 'yyyy-MM-dd');
date_till = Utilities.formatDate(date_till, 'GMT', 'yyyy-MM-dd');
var tableId = 'ga:*****';
// Make a request to the API.
var results = Analytics.Data.Ga.get(tableId, date_from, date_till, 'ga:newVisits', {});
if (results.getRows()) {
return results;
} else {
throw new Error('No views (profiles) found');
}
}
This is not solution to your question but it directs you to easy better solution to your problem if your interested!, you can easily setup this solution in an hour!
Details:
Better Than A writing our own script with Diligent Study and make Google scripts to fill Google Spreadsheet by Google Analytics data I use this Google Analytics Report Automation (Magic Script)
This Magic Script allow you to simplifies this process and makes it
easy to get the data you want so that you can focus on analysis and
reporting.
Custom API Dashboards - No Code Required it will save your burden for
Writing Your Own Script.
About the Error Try following things
Go to script editor, click on Resources > click on Use Google APIs.
Click on "Google APIs Console".
select APIs & auth > click on Registered apps.
Do Register your script project as web application.
select Certificate > Generate New Key .
This is an expected behavior. Custom Functions cannot ask users to give access to personal data. So they are not suitable for all types of services, specifically those which need authorization for personal data.
Check this url to know which services you can use - https://developers.google.com/apps-script/guides/sheets/functions#using_apps_script_services
Unlike most other types of Apps Scripts, custom functions never ask users to authorize access to personal data. Consequently, they can only call services that do not have access to personal data