Getting error while writing contact object using POST operation

I'am able to authenticate and getting oauth-token,token-secret,guid and session handle,when i use the same for retrieving contacts i'am able to get contacts but the same is not working when i run POST request in order to write contact. Wherein the yahoo app i created has read/write access for contacts When i run POST operation to write a contact object using REST api i'am getting error saying "Please provide valid credentials. OAuth oauth_problem=unable_to_determine_oauth_type ". Rest api used: http://social.yahooapis.com/v1/user/{guid}/contacts.

CODE: private static void createContact(YahooConfig config, YahooCredentials credentials) { String requestURI="http://social.yahooapis.com/v1/user/" credentials.getGUID() "/contacts"; try{ HttpClient client = new HttpClient(); PostMethod method=new PostMethod(requestURI); Map<String, String> oauthHeaders = new LinkedHashMap<String, String>(); Map<String, String> requestHeaders = new LinkedHashMap<String, String>(); Map<String, String> requestParams = new LinkedHashMap<String, String>(); requestParams.put("format", "xml"); StringBuilder requestStr= new StringBuilder(); requestStr.append(" name <value John</givenName<middleName/> Doe <prefix/><suffix/><givenNameSound/><familyNameSound/> co-workers "); OAuthUtil.signWithRequestParams("POST", config, credentials,"yahooapis.com","HMAC-SHA1", requestURI, oauthHeaders, requestHeaders, requestParams); OAuthHelper.setRequestElement(method, requestHeaders, requestParams); method.addRequestHeader("Content-Type", "application/xml;charset=UTF-8"); method.addRequestHeader("Accept","application/xml"); System.out.println("query Str : " method.getQueryString()); int statusCode= client.executeMethod(method); String response = method.getResponseBodyAsString(); System.out.println("Status code :" statusCode); System.out.println("Response : " response); }catch(Exception e){ e.printStackTrace(); } }

0 Replies

Recent Posts

in Suggestions for YDN