How to troubleshoot "Value cannot be null. Parameter name: baseUri" - google-app-engine

I need help diagnosing this error. Others get it on various platforms (youtube, for example) but seems not solved for most of them. For those who do report success, their solutions haven't work for me.
I'm using Google Drive API and I receive this error when attempting to upload to Google Drive.
My code was working fine for a long time; suddenly, I get this error. After research, I determined that I haven't reached a quota, and that these API are enabled:
Debuglet Controller API
Drive API
Google Cloud Dataflow API
Google Cloud Dataproc API
Google Cloud Deployment Manager API
Google Cloud Deployment Manager V2 API
Google Cloud Storage
Google Cloud Storage JSON API
Google Compute Engine Autoscaler API
Google Compute Engine Instance Group Manager API
Google Compute Engine Instance Group Updater API
Google Compute Engine Instance Groups API
Google Container Engine API
Google Machine Learning API
Here's my code:
string fileName = #"c:\temp\MyPicture.jpg";
string fileTitle = #"TEST-DELETE-ME.jpg";
string fileDescription = #"Test file name";
string fileType = "image/jpeg";
string parentId = "zmzmzmzmzmzmzmzmzmz";
Google.Apis.Drive.v2.DriveService service = (Google.Apis.Drive.v2.DriveService)Service;
Google.Apis.Drive.v2.Data.File body = new Google.Apis.Drive.v2.Data.File();
body.Title = fileTitle;
body.Description = fileDescription;
body.MimeType = fileType;
body.Parents = new List<ParentReference> { new ParentReference() { Id = parentId } };
byte[] byteArray = System.IO.File.ReadAllBytes(fileName);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
Google.Apis.Drive.v2.FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, fileType);
Google.Apis.Upload.IUploadProgress progress = request.Upload();
Google.Apis.Drive.v2.Data.File file = request.ResponseBody;
if (file == null)
{
//Here we are, and we shouldn't be!
//progress.exception.message =
//
//Value cannot be null.
//Parameter name: baseUri
}
When I look at Drive API settings, these are the configurations:
No icons (there are boxes to set 256x265, 128x128, 64x64, 32x32, and 16x16 all are blank)
The application name and short and long descriptions are all blank and optional.
For Drive Integration, all boxes and checkboxes are blank or unchecked. Specifically:
"Automatically show OAuth 2.0 consent..." is unchecked.
"Open URL" is blank.
Default and secondary MIME types and file extensions are blank
"Allow users to create new documents..." is unchecked
"Allow users to open multiple files..." is unchecked
"Allow users to open files that can be converted..." is unchecked
"This application can be launched and works properly in a mobile browser" is unchecked.
Users don't use the Google Drive UI to create documents via my application, and is not meant to be used on a mobile browser. My application only uploads PDF files to users' accounts.
My application has been working for months with no problems, now suddenly seeing this error.
I have tried disabling all API's and then re-enabling them. No dice.
I have tried using a new client id and secret. No dice.
I have tried using a new gmail address and creating a new client id and secret. No dice.
I can't possibly be the only person in the world with this problem. Can anyone help me troubleshoot this?

The underlying issue is like an authorization issue or some other error with the request. However, there's a bug in the .NET client that is masking the error.
See https://github.com/google/google-api-dotnet-client/issues/456

Related

Best SERVERLESS way to feed data from multiple Chrome extensions to a single Google Spreadsheet

I have a Chrome browser plugin which performs like a social media posts bookmarks collector (a click on a post captures it's author username, text, date, permalink and the plugin user who owns it). I'm looking for the most efficient, safest and SERVERLESS way to have [potentially] thousands of plugin end-users update, for each individual click on a post, a line in a Google spreadsheet.
With my limited knowledge I narrowed the options to webhooks:
Create a Google Apps simple webhook app that will listen to plugin packets.
Have the end-user plugins send each social-media post click data in JSON to the webhook.
Have the webhook Google App publish an RSS feed with all the data collected
Have the Google Spreadsheet regularly check for new RSS entries and update a new line for each.
What i'm not sure of is 1) whether a simple webhook can be created using Google Apps? 2) can this method be secure enough to prevent non-plugin entries to the RSS feed? and 3) is there a simpler more efficient way of achieving this end?
Your help will be much appreciated :-)
Thanks.
You can easily create Webhooks in Google Apps Script through the use of Webapps. As an example:
function doPost(e) {
if (e.postData && e.postData.type == 'application/json') {
var data = JSON.parse(e.postData.contents);
var author = data['author'];
var text = data['text'];
var date = data['date'];
var permalink = data['permalink'];
var user = data['user'];
// (...)
}
This example code will parse the data received through a JSON post request. Afterwards, you can insert it to your Spreadsheet and generate an RSS feed using XmlService (for more information on how to do it see this blog post). The RSS feed can be served using the doGet() method.

Flutter: Google Drive: File list always returns me 0

I want to retrieve list of files from a Google drive folder. Authentication happens through Service account. Here is my code to do the same:
final _credentials = new ServiceAccountCredentials.fromJson(r'''
{
"private_key_id": "b5-xxxx-17",
"private_key": "-----BEGIN PRIVATE KEY-----\nMI-xxxxk=\n-----END PRIVATE KEY-----\n",
"client_email": "drive-access#xxxx.iam.gserviceaccount.com",
"client_id": "100000000000",
"type": "service_account"
}
''');
final _SCOPES = [SheetsApi.DriveFileScope, SheetsApi.SpreadsheetsScope];
clientViaServiceAccount(_credentials, _SCOPES).then((http_client) {
DriveApi driveApi = DriveApi(http_client);
driveApi.files.list().then((files) {
print('kind: ' + files.kind);
print('list: ' + files.files.length.toString());
});
My log looks like this:
just: drive#fileList
list: 0
In Google Developers console, Google Drive API is enabled and service account it linked properly (as far as I can check).
But I also got another piece of code which writes some data to a spreadsheet, with hardcoded sheetID and that code is working fine.
Any help on what I am doing wrong here?
Retrieving files using Service account:
The service account is different from your Google account. This means that the Google Drive is also different between Service account and your account. So when the file is retrieved using Service account, please share the files in your Google Drive with the Service account. By this, the files in your Google Drive can be retrieved by the Service account.
Scopes:
In your script, DriveFileScope and SpreadsheetsScope are used as the scopes. DriveFileScope is https://www.googleapis.com/auth/drive.file. The official document says this scope as follows.
View and manage Google Drive files and folders that you have opened or created with this app
By this, in your script, how about modifying DriveFileScope as follows?
DriveReadonlyScope (https://www.googleapis.com/auth/drive.readonly)
DriveScope (https://www.googleapis.com/auth/drive)
Note:
I think that this scope can be also used for your situation.
DriveApi.driveMetadataReadOnlyScope (https://www.googleapis.com/auth/drive.metadata.readonly)
References:
Scopes for Google Sheets API, v4
Scopes for Drive API, v3

Listing Google Calendar ACLs using Calendar.Acl.list in Apps Script results in error "Execution failed: Not Found"

Trying to list and update the Google calendar ACLs using the code below in Google Apps script interface (script.google.com). I have enabled The Calendar API on the GSuite account and can see the API being hit (with 404s and 403s) in the developer console.
The calendarId listed in the code below is fake but, the one I am using does exist and works fine in the developer portal using the Try this API form.
https://developers.google.com/google-apps/calendar/v3/reference/acl/list
I assume I have the adequate authorization because I am logged in using the the same GSuite account on the developer portal and app scripts interface.
Are there any restrictions on the Google Apps Script environment or OAuth authorization that would prohibit this code from running only in Apps Script?
function test()
{
var calendar_acl_list;
calendar_acl_list = Calendar.Acl.list({calendarId: 'hannibal#domain.com'});
Logger.log('%s', calendars_acl_list);
}
It is possible that my simple code is not correct but, the error does not give enough information to troubleshoot. This is the error displayed in the View>Execution Transcript menu within Apps Script interface.
[17-09-26 14:13:31:492 PDT] Execution failed: Not Found (line 32, file "Code") [0.066 seconds total runtime]
Even though the code above is not working. The code below is:
function test2()
{
var calendars;
calendars = Calendar.CalendarList.list({maxResults: 100});
Logger.log('%s', calendars);
}
The proper usage of the Calendar.Acl.list method is:
calendarId = 'whatever#gmail.com'
calendars_acl_list = Calendar.Acl.list(calendarId);
Logger.log('%s', calendars_acl_list);

google apps from app engine

I want to produce a Google Apps document based on a (Google doc) template stored on the users Google Drive and some XML data held by a servlet running on Google App Engine.
Preferably I want to run as much as possible on the GAE. Is it possible to run Apps Service APIs on GAE or download/manipulate Google doc on GAE? I have not been able to find anything suitable
One alternative is obviously to implement the merge functionality using an Apps Script transferring the XML as parameters and initiate the script through http from GAE, but it just seem somewhat awkward in comparison.
EDIT:
Specifically I am looking for the replaceText script functionality, as shown in the Apps script snippet below, to be implemented in GAE. Remaining code is supported through Drive/Mail API, I guess..
// Get document template, copy it as a new temp doc, and save the Doc’s id
var copyId = DocsList.getFileById(providedTemplateId)
.makeCopy('My-title')
.getId();
var copyDoc = DocumentApp.openById(copyId);
var copyBody = copyDoc.getActiveSection();
// Replace place holder keys,
copyBody.replaceText("CustomerAddressee", fullName);
var todaysDate = Utilities.formatDate(new Date(), "GMT+2", "dd/MM-yyyy");
copyBody.replaceText("DateToday", todaysDate);
// Save and close the temporary document
copyDoc.saveAndClose();
// Convert temporary document to PDF by using the getAs blob conversion
var pdf = DocsList.getFileById(copyId).getAs("application/pdf");
// Attach PDF and send the email
MailApp.sendEmail({
to: email_address,
subject: "Proposal",
htmlBody: "Hi,<br><br>Here is my file :)<br>Enjoy!<br><br>Regards Tony",
attachments: pdf});
As you already found out, apps script is currently the only one that can access an api to modify google docs. All other ways cannot do it unless you export to another format (like pdf or .doc) then use libraries that can modify those, then reupload the new file asking to convert to a google doc native format, which in some cases would loose some format/comments/named ranges and other google doc features. So like you said, if you must use the google docs api you must call apps script (as a content service). Also note that the sample apps script code you show is old and uses the deptecated docsList so you need to port it to the Drive api.
Apps script pretty much piggy backs on top of the standard published Google APIs. Increasingly the behaviours are becoming more familiar.
Obviously apps script is js based and gae not. All the APIs apart from those related to script running are available in the standard gae client runtimes.
No code to check here so I'm afraid generic answer is all I have.
I see now it can be solved by using the Google Drive API to export (download) the Google Apps Doc file as PDF (or other formats) to GAE, and do simple replace-text editing using e.g. the iText library

302 status when copying data to another app in AppEngine

I'm trying to use the "Copy to another app" feature of AppEngine and keep getting an error:
Fetch to http://datastore-admin.moo.appspot.com/_ah/remote_api failed with status 302
This is for a Java app but I followed the instructions on setting up a default Python runtime.
I'm 95% sure it's an authentication issue and the call to remote_api is redirecting to the Google login page. Both apps use Google Apps as the authentication mechanism. I've also tried copying to and from a third app we have which uses Google Accounts for authentication.
Notes:
The user account I log in with is an Owner on all three apps. It's a Google Apps account (if that wasn't obvious).
I have a gmail account this is an Owner on all three apps as well. When I log in to the admin console with it, I don't see the datastore admin console at all when I click it.
I'm able to use the remote_api just fine from the command-line after I enter my details
Tried with both the Python remote_api built-in and the Java one.
I've found similar questions/blog posts about this, one of which required logging in from a browser, then manually submitting the ACSID cookie you get after that's done. Can't do that here, obviously.
OK, I think I got this working.
I'll refer to the two appIDs as "source" and "dest".
To enable datastore admin (as you know) you need to upload a Python project with the app.yaml and appengine_config.py files as described in the docs.
Either I misread the docs or there is an error. The "appID" inthe .yaml should be the app ID you are uploading to to enable DS admin.
The other appID in the appengine_config file, specifically this line:
remoteapi_CUSTOM_ENVIRONMENT_AUTHENTICATION = (
'HTTP_X_APPENGINE_INBOUND_APPID', ['appID'])
Should be the appID of the "source", ID the app id of where the data is coming from in the DS copy operation.
I think this line is what allows the source appID to be authenticated as having permissions to write to the "dest" app ID.
So, I changed that .py, uploaded again to my "dest" app ID. To be sure I made this dummy python app as default and left it as that.
Then on the source app ID I tried the DS copy again, and all the copy jobs were kicked off OK - so it seems to have fixed it.

Resources