How to fill Google form with C#

陌路散爱 提交于 2020-03-15 06:06:11

问题


The form is multipaged, like this and I tried to use POST request, but it works only for one-paged form, check this subject. Maybe there are another ways?


回答1:


Try this code.

WebClient client = new WebClient();
var nameValue = new NameValueCollection();
nameValue.Add("entry.xxx", "VALUE");// You will find these in name (not id) attributes of the input tags 
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("entry.xxx", "VALUE");
nameValue.Add("pageHistory", "0,1,2");//Comma separated page indexes
Uri uri = new Uri("https://docs.google.com/forms/d/e/[FORM_ID]/formResponse");
byte[] response = client.UploadValues(uri, "POST", nameValue);
string result = Encoding.UTF8.GetString(response);

I tried this with 3 pages. You can have any number of pages "i guess". This will submit the data directly and return "Success page from google forms".

EDIT

I Have not worked with google forms "like never", so was not able to find a proper way to do this if there is any, but this seems to work just fine.

Append this to your uri for multiple checkboxes

?entry.xxxx=Option+1&entry.xxxx=Option2 

entry.xxxx remains same for one question if you have multiple questions with check boxes then it would change to this

?entry.xxx=Option+1&entry.xxx=Option2&entry.zzz=Option+1&entry.zzz=Option2

value is the lable of your check box replace (whitespace) with (+) plus if any like in (Option 1)




回答2:


Puneet's answer was the only answer I've found on how to deal with checkboxes with multiple values. I tried to find a way to put multiple checkbox values in the body of the response instead of in the URL but could not.

In the spirit of his answer, I've made a GoogleFormSubmissionService in C# to make dealing with Google Forms easy in C#.

You can find it on my Gist here: Google Forms Submission Service in C#



来源:https://stackoverflow.com/questions/52398172/how-to-fill-google-form-with-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!