2013-02-13 20 views
8

Ho bisogno di aiuto con clojure and oauth.clojure OAuth e le credenziali

Sono rimasto bloccato a l'ultimo passo: la firma della richiesta con le credenziali.

(def credentials (oauth/credentials consumer 
            (:oauth_token access-token-response) 
            (:oauth_token_secret access-token-response) 
            :POST 
            "http://twitter.com/statuses/update.json" 
            {:status "posting from #clojure with #oauth"})) 

(http/put "http://twitter.com/statuses/update.json" 
      :query-params credentials) 

Questo è l'esempio di github.

Ora, dal Flickr API, ho questo test-url:

http://api.flickr.com/services/rest/?method=flickr.people.getPhotos 
&api_key=82d4d4ac421a5a22et4b49a04332c3ff 
&user_id=93029506%40N07&format=json&nojsoncallback=1 
&auth_token=72153452760816580-cd1e8e4ea15733c3 
&api_sig=b775474e44e403a79ec2a58d771e2022 

Non uso Twitter ... Io uso il Flickr API, e vuole ottenere le immagini di un utente.

La mia domanda è ora: come devo cambiare le credenziali che si inserisce l'url flickr? Sono anche confuso circa la :status ma quando elimino io ottenere un errore ...

+0

è che api_key dovrebbe essere segreto? 82d4 ...? –

+0

Il suo solo un TestKey e scade in un paio d'ore ... ma ho cambiato i numeri ora ... forse più sicuri;) – Nico

+0

Sarebbe utile se si dà il codice vero e proprio (chiavi sans) piuttosto che l'esempio Twitter. – ivant

risposta

3

L'esempio Twitter utilizza il metodo HTTP POST, ma per Flickr ci voglio GET e il Flickr API. Così facciamo

(def credentials (oauth/credentials consumer 
           (:oauth_token access-token-response) 
           (:oauth_token_secret access-token-response) 
           :GET 
           "http://api.flickr.com/services/rest/" 
           query-params)) 

Nell'esempio Twitter, quello che ho sostituito con query-params specifica quale ottenere pubblicato. È una mappa che sarà codificata in url in qualcosa come status=posting%20from%20%23clojure%20with%20%23oauth. Al contrario, la richiesta da parte della API si parla ha la seguente mappa per il non-OAuth query params:

(def query-params {:method "flickr.people.getPhotos" :format "json" :user_id "[email protected]" :nojsoncallback 1}) 

Ora tutto quello che dobbiamo fare è

(http/get "http://api.flickr.com/services/rest/" {:query-params (merge credentials query-params)}) 
Problemi correlati