1

I want to write a function for uploading photos to flickr as http://www.flickr.com/services/api/upload.api.html. I wrote the following code:

val http = new Http with thread.Safety
val uploadEndPoint = :/("api.flickr.com") / "services" / "upload"

then I sign the method using dispatch

def signUploadRequest(userParams: Map[String, String], accessToken: Token, verifier: String): Map[String, String] = {
    var map = userParams
    map += "api_key" -> consumerKey
    sign("", uploadEndPoint.toString, userParams, consumer, Some(accessToken), Some(verifier), Some(OAuth.oob))
  }

Then I call the following method:

def sendUploadRequest(reqParms: Map[String, String]) = { http(uploadEndPoint.POST <:< reqParms as_str) }

but I got the following error:

<rsp stat="fail">
    <err code="100" msg="Invalid API Key (Key has invalid format)" />
</rsp>

I use the same procedure for requests and it works fine. What is the problem with the Post?

Thanks, Feras

Urist McDev
  • 498
  • 3
  • 14
Feras Odeh
  • 9,136
  • 20
  • 77
  • 121

1 Answers1

1

I don't know this flickr api, but shouldn't the map pass as the request body ?

Another remark is that, they say that the photo can't be part of the signature (just in case the userParams contains its).

So, if you should use post's body instead of putting the map in the headers (which does <:<):

def sendUploadRequest(reqParms: Map[String, String]) = { http(uploadEndPoint << reqParms as_str) }

The << convert the request to post, using the given map as the payload. Note that using POST will set the Map body as empty.

Andy Petrella
  • 4,345
  • 26
  • 29
  • I don't use photo in the signature and when I changed the verb to << I got the following error: Authentication error: Unable to respond to any of these challenges: {} Exception in thread "main" dispatch.StatusCode: Unexpected response code: 401 oauth_problem=signature_invalid&debug_sbs=POST โ€“ Feras Odeh Feb 14 '12 at 11:41
  • Should I choose a different http executor for the post? โ€“ Feras Odeh Feb 14 '12 at 11:42
  • 1
    Looking there :http://www.flickr.com/services/api/auth.spec.html. at the 9.1 ยง, they say how to use auth. Some parameters must be provided as query params. So for those ones, api_key, and so on, use must use `<` โ€“ Andy Petrella Feb 14 '12 at 12:28