android - API key is always missing when I try to access MailChimp's api using Retrofit -


i'm sure non issue knows they're doing, first time using mailchimp's api , retrofit. basically, api key missing. have no idea mailchimp's proper url looks when including api key.

the url attempting is:

/3.0/lists/613cd953b2/members?user=email@gmail.com:apikey 

and others of variety

http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members

curl --request \

--url 'https://.api.mailchimp.com/3.0/' \

--user 'anystring:your_apikey'

this says attempting post.

here android / java code...

final okhttpclient client = new okhttpclient();     httplogginginterceptor interceptor = new httplogginginterceptor();     interceptor.setlevel(httplogginginterceptor.level.body);     client.interceptors().add(interceptor);       client.interceptors().add(new interceptor() {         @override         public com.squareup.okhttp.response intercept(chain chain) throws ioexception {             request original = chain.request();              request.builder requestbuilder = original.newbuilder()                    // .header("authorization", basic)                     .header("user", "email@gmail.com:apikey");              request request = requestbuilder.build();             return chain.proceed(request);         }     });      retrofit retrofit = new retrofit.builder()             .baseurl(base_url)             .client(client)             .addconverterfactory(gsonconverterfactory.create())             .build();      //create interface instance     mailchimpapi apiservice = retrofit.create(mailchimpapi.class);      email chimpemail = new email("hi@hi.hi");      call<email> call = apiservice.adduser(chimpemail);     call.enqueue(new callback<email>() {         @override         public void onresponse(response<email> response, retrofit retrofit) {             int statuscode = response.code();             //log.d("tag", "enter void");             log.d("tag", statuscode + "");             log.d("tag", client.tostring());         }          @override         public void onfailure(throwable t) {             log.d("tag", t.tostring());         }     }); 

and how define interface method

@post("/3.0/lists/613cd953b2/members") call<email> adduser(@body email email); 

and retrofit log...

d/okhttp: --> post /3.0/lists/613cd953b2/members http/1.1 d/okhttp: {"email_address":"hi@hi.hi","merge_fields":{"fname":"","lname":""},"status":""} d/okhttp: --> end post (79-byte body) d/okhttp: <-- http/1.1 401  (299ms) d/okhttp: okhttp-selected-protocol: h2 d/okhttp: server: nginx d/okhttp: content-type: application/problem+json; charset=utf-8 d/okhttp: x-request-id: 6b6ca6a9-c141-45fc-8de7-ec0922892bbf d/okhttp: link: <https://us12.api.mailchimp.com/schema/3.0/problemdetaildocument.json>; rel="describedby" d/okhttp: vary: accept-encoding d/okhttp: date: tue, 05 jan 2016 21:21:45 gmt d/okhttp: set-cookie: _avesta_environment=prod; path=/ d/okhttp: okhttp-sent-millis: 1452028904738 d/okhttp: okhttp-received-millis: 1452028904830 d/okhttp: {"type":"http://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"api key missing","status":401,"detail":"your request did not include api key.","instance":""} d/okhttp: <-- end http (193-byte body) 

i not using basic authentication properly. followed tutorial

https://futurestud.io/blog/android-basic-authentication-with-retrofit

and fixed error! yay new errors!

also future people, maybe might you.

basic authorization isn't way describe something! it's actual concept , implementable! haha


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -