cloudyr / MTurkR

R Client for the MTurk Requester API
https://cloud.r-project.org/package=MTurkR
91 stars 18 forks source link

ExternalQuestion Survey example fails with InvalidParameterValue #84

Closed julianheinrich closed 9 years ago

julianheinrich commented 9 years ago

First of thanks: thanks for this great package!

I'm trying to create a survey following the example. However, when I copy and paste the code given for the ExternalQuestion:

newhittype <- 
  RegisterHITType(title="10 Question Survey",
                  description="Complete a 10-question survey about news coverage and your opinions",
                  reward=".20", 
                  duration=seconds(hours=1), 
                  keywords="survey, questionnaire, politics")
eq <- GenerateExternalQuestion(url="https://www.example.com/myhit.html",frame.height="400")
CreateHIT(hit.type = newhittype, 
          question = eq$string, 
          expiration = seconds(1), 
          assignments = 1)

I get the following error:

Request NA not valid for API request:
https://mechanicalturk.sandbox.amazonaws.com/?Service = AWSMechanicalTurkRequester
                                             &AWSAccessKeyId = secret
                                             &Operation = CreateHIT
                                             &Timestamp = 2015-05-05T01:04:50Z
                                             &Signature = WtIAuM%2FcNqZ%2B6Ua4TdM5FhC%2B9HI%3D
                                             &HITTypeId = 32TFGTUJLO3JLR3RLESP8P2NN40IPG
                                             &Question = %3CExternalQuestion%20xmlns%3D%22http%3A%2F%2Fmechanicalturk.amazonaws.com%2FAWSMechanicalTurkDataSchemas%2F2006-07-14%2FExternalQuestion.xsd%22%3E%0A%20%20%3CExternalURL%3Ehttps%3A%2F%2Fwww.example.com%2Fmyhit.html%3C%2FExternalURL%3E%0A%20%20%3CFrameHeight%3E400%3C%2FFrameHeight%3E%0A%3C%2FExternalQuestion%3E%20
                                             &LifetimeInSeconds = 86400
                                             &MaxAssignments = 1 

Error (InvalidParameterValue): Value (ÈJ Jû) for parameter QueryStringParameter is invalid. Invalid or illegal XML character specified
API Operation:  CreateHIT 
RequestId:      NA 
Valid?          FALSE 
Request URL:    https://mechanicalturk.sandbox.amazonaws.com/?Service=AWSMechanicalTurkRequester
AWSAccessKeyId=AKIAIMO4QNO42XBUTF5A
Operation=CreateHIT
Timestamp=2015-05-05T01:04:50Z
Signature=WtIAuM/cNqZ+6Ua4TdM5FhC+9HI=
HITTypeId=32TFGTUJLO3JLR3RLESP8P2NN40IPG
Question=<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
  <ExternalURL>https://www.example.com/myhit.html</ExternalURL>
  <FrameHeight>400</FrameHeight>
</ExternalQuestion> 
LifetimeInSeconds=86400
MaxAssignments=1 https://mechanicalturk.sandbox.amazonaws.com/?Service=AWSMechanicalTurkRequester
AWSAccessKeyId=AKIAIMO4QNO42XBUTF5A
Operation=CreateHIT
Timestamp=2015-05-05T01:04:50Z
Signature=WtIAuM/cNqZ+6Ua4TdM5FhC+9HI=
HITTypeId=1
Question=<ExternalQuestion xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2006-07-14/ExternalQuestion.xsd">
  <ExternalURL>https://www.example.com/myhit.html</ExternalURL>
  <FrameHeight>400</FrameHeight>
</ExternalQuestion> 
LifetimeInSeconds=86400
MaxAssignments=1XML Response:
Error in file.exists(file) : invalid 'file' argument
In addition: Warning message:
In CreateHIT(hit.type = newhittype, question = eq$string, expiration = seconds(1),  :
  Invalid Request

Note that I'm using the sandbox as per options() and that I replaced the key in the snippet above. I also tested credentials and get my account balance (for the sandbox):

> AccountBalance()
Balance: $10,000.00

Am I missing something here?

leeper commented 9 years ago

Sorry, this is an error in the example (I've fixed it now). Everything is correct until you get to CreateHIT:

CreateHIT(hit.type = newhittype$HITTypeId, 
          question = eq$string, 
          expiration = seconds(1), 
          assignments = 1)

Note the addition of $HITTypeId to the first argument. Let me know if that doesn't work for you.

julianheinrich commented 9 years ago

That works! Thanks very much!

leeper commented 9 years ago

Okay, great. Sorry about that.