如何使用c# API在amazon mturk上创建新的qualiationtype

本文关键字:创建 qualiationtype mturk amazon 何使用 API | 更新日期: 2023-09-27 18:18:18

我正在尝试创建一个新的qualificationtype,工人必须回答一个问题才能获得资格。下面是我的c#代码。我在c# api中使用createQualificationType方法时出现错误。请帮助。

using System;
using System.Collections.Generic;
using System.Text;
using Amazon.WebServices.MechanicalTurk;
using Amazon.WebServices.MechanicalTurk.Domain;
namespace CreateHITExample
{
    class Program
    {
        static SimpleClient client = new SimpleClient();
        static void Main(string[] args)
        {
            CreateNewHIT();
        }
        static void CreateNewHIT()
        {
            **QuestionFormQuestion** question = new QuestionFormQuestion();
            question.IsRequired = true;
            question.QuestionIdentifier = "1";
            **ContentType qnContent = new ContentType();**
            QualificationType qualType = client.CreateQualificationType("MyQual2", string.Empty, "My Qualification Type", QualificationTypeStatus.Active, 0, **question**, "680", 600, true, 100);
            string qualTypeId = qualType.QualificationTypeId;
            Console.WriteLine("Created Qualification Type ID 2: {0}", qualTypeId);
        }
    }
}

我必须将问题对象作为参数传递给CreateQualificationType方法。从上面的代码中可以看到,question对象属于QuestionFormQuestion类。

下面的类定义可能会有所帮助。

QuestionFormQuestion来自AWS MTurk dotnet API的类定义:

public class QuestionFormQuestion
    {
        public QuestionFormQuestion();
        public AnswerSpecificationType AnswerSpecification { get; set; }
        public string DisplayName { get; set; }
        public bool IsRequired { get; set; }
        [XmlIgnore]
        public bool IsRequiredSpecified { get; set; }
        **public ContentType QuestionContent { get; set; }**
        public string QuestionIdentifier { get; set; }
    }

实际的问题文本放入QuestionContent属性中,该属性的类型为"ContentType"。

ContentType来自AWS MTurk dotnet API的类定义:

public class ContentType
    {
        public ContentType();
        [XmlChoiceIdentifier("ItemsElementName")]
        [XmlElement("Application", typeof(ApplicationContentType))]
        [XmlElement("Binary", typeof(BinaryContentType))]
        [XmlElement("FormattedContent", typeof(String))]
        [XmlElement("Text", typeof(String))]
        [XmlElement("Title", typeof(String))]
        public object[] Items { get; set; }
        [XmlElement("ItemsElementName")]
        [XmlIgnore]
        public ItemsChoiceType[] ItemsElementName { get; set; }
    }

我必须将实际问题句移动到ContentType对象的[XmlElement("Text", typeof(String))]元素。我不知道这样做的语法。请帮助。

如何使用c# API在amazon mturk上创建新的qualiationtype

我使用Ruby SDK遇到相同的ValueException错误消息,直到我发现(与所有API文档示例不同,它显示XML是预期的)CreateHit期望一个哈希,而不是一些参数的XML (XML for Question,但哈希for qualiationrequirement例如)。

在我的情况下,它拒绝了一个qualiationrequirement当我提供它XML像他们在文档中显示,但它工作时,我提供它作为一个哈希。

但是由于错误消息是相同的,我怀疑这可能也是您遇到的问题。(错误与语言无关…它不是来自您的SDK,而是当您的SDK提交HIT时从AWS返回的内容。

# does NOT work:
usa_qualification = 'XML STRING LIKE AWS DOCS GIVE'
# DOES work:
usa_qualification = { 
  :QualificationTypeId => "00000000000000000071",
   :Comparator => "EqualTo",
   :LocaleValue => { :Country => "US"},
result = mturk.createHIT( :Title => title,
   ...
  :QualificationRequirement =>  usa_qualification , 
   ...