Creating sheet via execution API - android

I'm trying to create a google sheets document via script, and I'm using the execution API example google provides here:
https://developers.google.com/apps-script/guides/rest/quickstart/android
The only change I've made was a line on the script:
function getFoldersUnderRoot() {
var sheet = SpreadsheetApp.create("MySheet"); //This line.
var root = DriveApp.getRootFolder();
var folders = root.getFolders();
var folderSet = {};
while (folders.hasNext()) {
var folder = folders.next();
folderSet[folder.getId()] = folder.getName();
}
return folderSet;
}
But, even though i can run the code correctly, it just doesnt create the sheet. Maybe some authorization problem? I couldnt find it... Id thank you so much for your help... I really need this to my project.

Based from this guidelines, before using the API you need to do the following to meet the above requirements:
Create an Apps Script project to call, with the functions you want to use. The API can also be used to call existing scripts that were created for other projects. Open the project in the Apps Script editor.
Deploy the script project for execution by selecting Publish > Deploy as API executable. Choose a version (or create a new one) and who has access, then click Deploy. The new dialog that opens shows your script's ID, listed under "Current API ID". Make note of this ID — you need to enter it into the application code so that the API knows which script to call. If you need to find it again later, select Publish > Deploy as API executable in the code editor to see it.
Choose a Cloud Platform project and ensure both the calling application and the target script share it. If you use the script's default Cloud Platform project, the calling application should use that project to set up its OAuth credentials. This requires you to have access to the default Cloud Platform project, which may not be the case if the script resides in Team Drive. If you are using a new or existing Cloud Platform Project, you need to switch the Apps Script project to use it if you have not done so already.
Enable the Google Apps Script Execution API in the Cloud Platform project. You can find directions for doing this in the Execution API Java Quickstart.
Create a valid Client ID and client secret for the application in the Cloud Platform project. This is covered in the Execution API Java Quickstart.
In the application code, generate an OAuth access token for the API call. This is not a token the API itself uses, but rather one the script requires. The token must be built using the Client ID and the scopes from the script (in the editor, under File > Project properties > Scopes). This also requires prompting the user to authorize the script. The Google client libraries, while not strictly necessary, can greatly assist in handling OAuth for the application.
Hope this helps.

Related

How to Implement Segment.io via GTM for Android/iOS?

I am trying to implement Segment on our apps (both Android and iOS) via GTM containers for both OS.
However, since I m not a app developer I m struggling to understand how to use the function call in GTM, picture below
Given that this is the code to add an Android app as source for Segment, does anyone know how to proceed in the Tag configuration:
Step 1. Add the Analytics dependency to your build.gradle
The recommended way to install the library for Android is with a build system like Gradle. This makes it dead simple to upgrade versions and add integrations. The library is distributed via wwww Maven Central. Simply add the analytics module to your build.gradle:
dependencies {
compile 'com.segment.analytics.android:analytics:4.+'
}
Need more info? Read the complete Android documentation.
Step 2. Initialize the Client
We recommend initializing the client in your Application subclass.
// Create an analytics client with the given context and Segment write key.
Analytics analytics = new Analytics.Builder(context, "0Et0DSpva5mxEGNCr7W0vEjiprAWFvTm")
// Enable this to record certain application events automatically!
.trackApplicationLifecycleEvents()
// Enable this to record screen views automatically!
.recordScreenViews()
.build();
// Set the initialized instance as a globally accessible instance.
Analytics.setSingletonInstance(analytics);
Automatically tracking lifecycle events (Application Opened, Application Installed, Application Updated) is optional, but highly recommended to hit the ground running with core events!
This only installs the Segment integration. This means that all your data will be sent server side to tools. If you need to bundle additional integrations client side, you’ll need to take some additional steps.
Step 3. Add Permissions to AndroidManifest.xml
<!-- Required for internet. -->
<uses-permission android:name="android.permission.INTERNET" />
You do not deploy an SDK via GTM.
Have your app devs following Segment's guide here: https://segment.com/docs/connections/sources/catalog/libraries/mobile/ios/quickstart/

Fragment not Generated in AppSync Sample App

I'm going through the sample app for AppSync as described here.
I found a sample Android client app on GitHub here and am trying to just get it to run with my data but for some reason the fragments aren't being generated.
events.graphql has what appears to be the events fragment definition.
fragment Event on Event {
id
description
name
when
where
comments {
items {
eventId
commentId
content
createdAt
}
}
I've tried adding it to the schema in the appsync web interface and it saves the schema but then doesn't actually add the fragment. I'm just now trying GraphQL tonight so I'm not really sure where to even put the fragment definition and Google doesn't seem to have anything about this.
Going to need more information here before answering, but I'm working on the same sample project and was able to get it working so I might be of some help.
Is your project syncing and building? That's a good first step.
It looks like your .graphql files are being autogenerated in your app-> source -> appsync -> com file, but the classes are not being generated in the app -> build -> source -> appsync -> com folder.
Something I learned in the process of working on this project was that it's important to have all your resolvers and the backend set up fairly completely in the AWS console before calling the amplify add api command. Have you setup the back end with resolvers?
If you have and it's still not working, try running in the app terminal amplify gql-compile then running amplify pushto pull the data back into your app from the console, then resync and rebuild as necessary. This should build your Query/Mutation/Subscription classes for you, as well as the Fragment.class, which are the resolvers in your program for the .graphql queries/etc that you want to run in your application.
If that doesn't work, make sure you've completed all the necessary steps in the amplify API like amplify add api, amplify update api. It appears that you've already done that since you have generated .graphql files in the app-> source directory, but in case you haven't, those are first steps. You can also check to make sure that you're actually connected to the DB (and correct api in the console) by running amplify status. Are you connected to the console API that you need to be connected to?
As a last resort, you can copy the Event.class file from github and paste it into the appropriate file/subdirectory, along with the rest of the Query/Mutation/etc .class files that should have been generated by the ApolloGraphql plugin.

Firebase authentification works but I get error when using the Google Text to Speech API

I've set up a small android and firebase app... Authentification works like a charm, and in the firebase console, I can see my user, logged in with the Google account.
Now I am trying to experiment a little with the Text to Speech api, and in doing so, I followed this tutorial:
https://github.com/GoogleCloudPlatform/java-docs-samples/tree/master/texttospeech/cloud-client
I managed to make the small java app work, by setting the GOOGLE_APPLICATION_CREDENTIALS Environment variable (I followed this tutorial for this step: https://cloud.google.com/docs/authentication/getting-started), but I am not sure what I need to do to make that code work in the Android app where the users are authentificated..
The Error that I get when trying to make a call to the TextToSpeech API is:
The Application Default Credentials are not available. They are
available if running in Google Compute Engine. Otherwise, the
environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined
pointing to a file defining the credentials. See
https://developers.google.com/accounts/docs/application-default-credentials
for more information.
The error mentioned comes from the line:
TextToSpeechClient textToSpeechClient = TextToSpeechClient.create();
This error appears because of the fact that on the android emulator I don't have access to the credentials that are set as environment variable in my OS..So I have to provide the credentials in another way.
In the case of other Google APIs, like Storage, I found out that this can be done like this:
// You can specify a credential file by providing a path to GoogleCredentials.
// Otherwise credentials are read from the GOOGLE_APPLICATION_CREDENTIALS environment variable.
GoogleCredentials credentials = GoogleCredentials.fromStream(new FileInputStream(jsonPath))
.createScoped(Lists.newArrayList("https://www.googleapis.com/auth/cloud-platform"));
Storage storage = StorageOptions.newBuilder().setCredentials(credentials).build().getService();
I managed to create the GoogleCredentials object with the contents of the json file, however the TextToSpeech client doesn't seem to provide a functionality similar to this:
StorageOptions.newBuilder().setCredentials(credentials).build()
So my question is....is there a way to provide the Credentials object to the TextToSpeech client?
Thanks
Currently, there is not a way to provide credentials to the TTS Client from this page.
Due to Security / Auth reasons, I believe the best suggested approach is to use Firebase Functions.
Get the Text
Call Firebase Functions
Have Firebase Functions call the TTS API
Return the results.
This way, no keys are leaked inside the application and you can use Firebase Auth.
Let me know if that helps!
Update:
Option 2: iOS Tutorial (should be adaptable to Android)
Get the Text
Call Firebase Functions
Have Firebase Functions return an OAuth2 Token
Use the token directly with the API

GoogleJsonResponseException : 404 not found / 401 Unauthorized in settings google apps endpoint engine backend in android Google Cloud Save

Hello friends i starting learn about google cloud save, so i create apps and follows step given in google.developer and i am also using their example using link https://github.com/GoogleCloudPlatform/solutions-mobile-backend-starter-android-client
and https://developers.google.com/cloud/samples/mbs/android/ but i think i face some problem in autentication, and got error com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
and some time : com.google.api.client.googleapis.json.GoogleJsonResponseException: 401 Unautorized
i just want to store my game score using google cloud save.please any one can give me solution about it or any related links ? thanks in advance.
I find my own solution :
I follow following step :
hope these help you if necessary :
Assume you are created project on https://console.developers.google.com/
and follow necessary step
like
In API & AUTH -->APIs
Google cloud Storage and Google cloud Messaging for android and whatever you need On
In API & AUTH -->Credentials
Create new Client ID
for
-->Client ID for Android Application and
-->Client ID for Web Application
-->Key for server applications
(1) Open the Google API Console and make sure your Mobile Backend project is the active project by selecting it in the projects pulldown menu in the top left.
(2) Click Services.
(3) Locate Google Cloud Messaging for Android in the list of available services, and click the ON toggle.
(4) Accept the Terms of Services if you have not already.
(5) Click API Access in the top left of the API console.
(6) Scroll down to click Create new Server key... You don't need to supply any IP values in this form. (Using a server key allows you to whitelist IP addresses).
(7) Click Create.
(8) Locate the API key within the Key for server apps form and copy this key to the clipboard.
(9) Navigate to .appspot.com. This will bring you to your Mobile Backend Starter settings configuration page.
(If not find then find from : click on your created project from the https://console.developers.google.com/ click on your created project Monitoring-->overview-->find Mobile Backend Starter from the bottom- of the screen click on that )
(10) Follow all three step of Deployment steps:
-->Deploy the backend
-->Open (for development use only) the backend to accept incoming requests via Settings
click on Settings-->Mobile Backend settings-->
---> Radio button on of **Secured by Client IDs (Recommended)**
---> Enter **Android Client Id, and Web Client id**
---> Google Cloud Messaging and iOS Push Notification **Enabled**
--->**Save**
-->download Sample Project if necessary
In sample project open Const.java file
Enter project_id,
Project_number,
Web_client_id(enter client_id_for_web_application here )
public static final boolean IS_AUTH_ENABLED = **true**;
public static final boolean LOCAL_ANDROID_RUN = **true**;
public static final String ENDPOINT_ROOT_URL = "https://" + PROJECT_ID
+ ".appspot.com/_ah/api/";
If Necessary go to :
App Engine Console -> Main -> Versions. ( https://appengine.google.com/ )
select your project
There you will see a list of versions with a Make Default button below. Select the radio button for the latest version and press the make default button, wait a minute or so, and try your call again.
Note that even if you have only one version that is already set as the default this solution should still work.
You may have to do this again the next time you deploy to app engine.
Hope my above step helping to anyone.
Faced this error when I had not deployed the latest version of backend to the google app engine. HTH

Moodle Function API doc over REST

I am trying to develop a Moodle Android app. I am using MoodleREST source code for my reference.Is there any other documentation on Moodle site which documents moodle core webservice functions with their required params.
I have found list of functions here http://docs.moodle.org/dev/Web_services_Roadmap but could not get proper documentation on how to call these functions with required params from mobile client using REST.
I am new to moodle and still learning it, so my question can be a little naive so please bear with it :)
This could be helpful http://docs.moodle.org/dev/Creating_a_web_service_client
And if you have some administrator access to Moodle, go to
yourmoodle/admin/webservice/documentation.php , or
Administration > Plugins > Web services > API Documentation.
There is API with documentation. (Dont know if there is better way though :/)
D.
AIUI you need admin to access the most comprehensive web service API, as described by #Dolfa. You'll need these docs and/or the source if you're developing against their REST API. The API docs are generated from the source, presumably so they accurately reflect the API in the installed version.
You could:
Browse the code on github
Clone the version you intend to program against so you can browse the code locally
Install it and give yourself admin so you can browse the API docs.
If you don't want to go through the hassle of setting up a local Moodle instance, you may be able to figure out a way to run the php that generates the docs.
Once you have a rough idea of an API call, you can often find out the details by looking at responses to command-line requests e.g.
curl 'https://your.domain/webservice/rest/server.phpmoodlewsrestformat=json' --data 'wsfunction=core_enrol_get_users_courses&wstoken=[your_ws_token]' --compressed | python -m "json.tool"
gives the response
{
"debuginfo": "Missing required key in single structure: userid",
"errorcode": "invalidparameter",
"exception": "invalid_parameter_exception",
"message": "Invalid parameter value detected"
}
indicating that the function requires a userid=[userid] argument.

Categories

Resources