1

Can we access google survey forms through REST API for Android and POST filled data in google survey through Android?

suresh
  • 87
  • 1
  • 10

1 Answers1

0

there is a java library here and it can be implemented like this:

Assuming you already have setup the survey API on your developer console.

You bind the library to your project:

implementation 'com.google.apis:google-api-services-surveys:v2-rev16-1.25.0'.

If you use Gson as your json parser, you need to exclude Jackson, since it comes with the survey java library. So then your gradle entry looks like this:


implementation("com.google.apis:google-api-services-surveys:v2-rev16-1.25.0") {
        exclude module: 'google-http-client-jackson2'
        exclude module: 'commons-logging'
        exclude module: 'httpcore'
        exclude module: 'httpclient' // excluding apache dependencies, too, since we don't need them.
    }

In order to use Gson with the survey API, you bind the gson google api client:

implementation "com.google.api-client:google-api-client-gson:1.28.0"

With that, you are able to execute your surveys through:

...

private void sendSurvey() {
    Survey mySurvey = new Survey().set("Hello", "World");
    new SendSurveyAsyncTask().execute(mySurvey);
}

...
private static class SendSurveyAsyncTask extends AsyncTask<Survey, Void, Boolean> {

        @Override
        protected Boolean doInBackground(Survey... surveys) {
            try {
                // using the NetHttpTransport here. You could even write your own retrofit transport for that, if you want.
                // See https://developers.google.com/api-client-library/java/google-http-java-client/android
                new Surveys.Builder(new NetHttpTransport(), new GsonFactory(), null)
                        .build()
                        .surveys()
                        .insert(surveys[0])
                        .execute();
            } catch (IOException e) {
                Log.e("SendSurveyAsyncTask", "oops", e);
                return false;
            }
            return true;
        }

        @Override
        protected void onPostExecute(Boolean result) {
            if (result) {
                Log.d("SendSurveyAsyncTask", "whoo!");
            } else {
                Log.d("SendSurveyAsyncTask", "boo!");
            }
        }
    }

hope it helps :)

cheers

thehayro
  • 1,516
  • 2
  • 16
  • 28