Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example not working #4

Open
nightrome opened this issue May 24, 2016 · 1 comment
Open

Example not working #4

nightrome opened this issue May 24, 2016 · 1 comment

Comments

@nightrome
Copy link

nightrome commented May 24, 2016

I tried the example with my access keys, but there seem to be several errors. Some things I had to fix:
[1] You didn't urlencode the "question", which results in a bug if it includes whitespaces.
[2](and following) You forgot the brackets () around the ternary if-then-else operator. Therefore these fields are missing in the request..

Now at least the basic example works..

[1] https://github.com/jackbot/PHP-Mechanical-Turk/blob/master/MechanicalTurk.class.php#L59
[2] https://github.com/jackbot/PHP-Mechanical-Turk/blob/master/MechanicalTurk.class.php#L55

Now the createHit function looks like this:

`
public function createHit($question, $params = null) {

    $ts = $this->Unix2UTC(time());
    $url = $this->startUrl();
    $url .= '&Operation=CreateHIT';
    $url .= '&Signature=' . $this->generateSignature($this->MTURK_SERVICE, 'CreateHIT', $ts);
    $url .= '&Timestamp=' . $ts;
    $url .= '&Title=' . (isset($params['title']) ? urlencode($params['title']) : urlencode($this->defaults['title']));
    $url .= '&Description=' . (isset($params['description']) ? urlencode($params['description']) : urlencode($this->defaults['description']));
    $url .= '&Reward.1.Amount=' . (isset($params['reward']) ? urlencode($params['reward']) : $this->defaults['reward']);
    $url .= '&Reward.1.CurrencyCode=' . (isset($params['reward_currency']) ? urlencode($params['reward_currency']) : $this->defaults['reward_currency']);
    $url .= '&Question=' . (($question != null) ? urlencode($question) : urlencode($defaults['question']));
    $url .= '&AssignmentDurationInSeconds=' . $this->defaults['duration'];
    $url .= '&AutoApprovalDelayInSeconds=' . $this->defaults['auto_approve'];
    $url .= isset($params['qualification_requirement']) ? $this->generateQualificationRequirement($params['qualification_requirement']) : $this->generateQualificationRequirement($this->defaults['qualification_requirement']);
    $url .= '&LifetimeInSeconds=' . (isset($params['lifetime']) ? urlencode($params['lifetime']) : $this->defaults['lifetime']);
    $url .= '&Keywords=' . (isset($params['keywords']) ? urlencode(implode(', ', $params['keywords'])) : urlencode(implode(', ', $this->defaults['keywords'])));
    if (isset($params['requester_annotation'])) {
        $url .= '&RequesterAnnotation=' . $params['requester_annotation'];
    } else if (isset($defaults['requester_annotation'])) {
        $url .= '&RequesterAnnotation=' . $defaults['requester_annotation'];
    }

    $response = file_get_contents($url);
    return $response;
}

`

@jackbot
Copy link
Owner

jackbot commented May 24, 2016

Thanks for this. I am no longer maintaining this repo (as stated in the readme), but if you put your changes in a PR I'll merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants