Невозможно получить ответ в таблице Google - PullRequest
0 голосов
/ 08 октября 2018

Я создаю приложение для получения отзывов пользователей и форму Google для получения данных из приложения в электронной таблице.Приложение успешно скомпилировано, и когда я заполняю форму и отправляю ... я получаю успешный ответ, но когда я открываю формы Google или электронную таблицу с тем же ответом, ни один ответ не был записан.

Вот моя основная активность

public class MainActivity extends AppCompatActivity {

    public static final MediaType FORM_DATA_TYPE
            = MediaType.parse("application/x-www-form-urlencoded; charset=utf-8");
    //URL derived from form URL
    public static final String URL="https://docs.google.com/forms/d/e/1FAIpQLSdatlKheW5G_H8g9DCD8_2K1Ltytb4Fn64erYleewN8PWB1vQ/viewform";
    //input element ids found from the live form page
    public static final String EMAIL_KEY="entry.1725271100";
    public static final String SUBJECT_KEY="entry.161281878";
    public static final String MESSAGE_KEY="entry.1798953063";

    private  Context context;
    private EditText emailEditText;
    private EditText subjectEditText;
    private EditText messageEditText;

    @Override
    protected void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //save the activity in a context variable to be used afterwards
        context =this;

        //Get references to UI elements in the layout

        emailEditText = (EditText)findViewById(R.id.email_input);
        subjectEditText = (EditText)findViewById(R.id.name_input);
        messageEditText = (EditText)findViewById(R.id.feedback_input);

        findViewById(R.id.submit_button).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //Make sure all the fields are filled with values
                if(TextUtils.isEmpty(emailEditText.getText().toString()) ||
                        TextUtils.isEmpty(subjectEditText.getText().toString()) ||
                        TextUtils.isEmpty(messageEditText.getText().toString()))
                {
                    Toast.makeText(context,"All fields are mandatory.",Toast.LENGTH_LONG).show();
                    return;
                }
                //Check if a valid email is entered
                if(!android.util.Patterns.EMAIL_ADDRESS.matcher(emailEditText.getText().toString()).matches())
                {
                    Toast.makeText(context,"Please enter a valid email.",Toast.LENGTH_LONG).show();
                    return;
                }

                //Create an object for PostDataTask AsyncTask
                PostDataTask postDataTask = new PostDataTask();

                //execute asynctask
                postDataTask.execute(URL,emailEditText.getText().toString(),
                        subjectEditText.getText().toString(),
                        messageEditText.getText().toString());
            }
        });
    }

    //AsyncTask to send data as a http POST request
    private class PostDataTask extends AsyncTask<String, Void, Boolean> {

        @Override
        protected Boolean doInBackground(String... contactData) {
            Boolean result = true;
            String url = contactData[0];
            String email = contactData[1];
            String subject = contactData[2];
            String message = contactData[3];
            String postBody="";

            try {
                //all values must be URL encoded to make sure that special characters like & | ",etc.
                //do not cause problems
                postBody = EMAIL_KEY+"=" + URLEncoder.encode(email,"UTF-8") +
                            "&" + SUBJECT_KEY + "=" + URLEncoder.encode(subject,"UTF-8") +
                            "&" + MESSAGE_KEY + "=" + URLEncoder.encode(message,"UTF-8");
            } catch (UnsupportedEncodingException ex) {
                result=false;
            }

            /*
            //If you want to use HttpRequest class from http://stackoverflow.com/a/2253280/1261816
            try {
            HttpRequest httpRequest = new HttpRequest();
            httpRequest.sendPost(url, postBody);
        }catch (Exception exception){
            result = false;
        }
            */

            try{
                //Create OkHttpClient for sending request
                OkHttpClient client = new OkHttpClient();
                //Create the request body with the help of Media Type
                RequestBody body = RequestBody.create(FORM_DATA_TYPE, postBody);
                Request request = new Request.Builder()
                        .url(url)
                        .post(body)
                        .build();
                //Send the request
                Response response = client.newCall(request).execute();
            }catch (IOException exception){
                result=false;
            }
            return result;
        }

        @Override
        protected void onPostExecute(Boolean result){
            //Print Success or failure message accordingly
            Toast.makeText(context,result?"Message successfully sent!":"There was some error in sending message. Please try again after some time.",Toast.LENGTH_LONG).show();
        }

    }
}

Пожалуйста, помогите
Заранее спасибо.

...