0

Get Contacts

I got the access token, Access token secret and GUID

but how to get Contacts with all these?

anybody got an example?

by
4 Replies
  • QUOTE (Steven @ Jun 28 2010, 10:56 AM) <{POST_SNAPBACK}>
    I got the access token, Access token secret and GUID

    but how to get Contacts with all these?

    anybody got an example?


    iam also having same problem,please help me
    0
  • Have you already looked through the Contacts API documentation? It's pretty detailed and includes examples. Please let me know whether that did the job or if you need further support.
    0
  • QUOTE (Erik @ Aug 11 2010, 08:14 AM) <{POST_SNAPBACK}>
    Have you already looked through the Contacts API documentation? It's pretty detailed and includes examples. Please let me know whether that did the job or if you need further support.

    That's true, but what about the Authorization header of the GET request? When try to retrieve the contacts I always get the "token_rejected" error. I think I provide the values correctly for the Authorization header, yet I still get the error all the times
    0
  • it should be something like this. just copy it. but there is something wrong with it. let me know if you figure it out.

    private void getAllContacts() {
    
    
        HttpClient httpclient = new DefaultHttpClient();
    
        String host_url = "http://social.yahooapis.com/v1/user/" + mUSER_GUID+ "/contacts";
    
        String nonce = ""+System.currentTimeMillis();
        String timeStamp = ""+(System.currentTimeMillis()/1000L);
    
    
    
    
        try{
            String params = "?realm=yahooapis.com" 
                    + "&oauth_consumer_key=" + CONSUMER_KEY
                    + "&oauth_nonce="+nonce
                    + "&oauth_signature_method="+"HMAC-SHA1"
                    + "&oauth_timestamp="+timeStamp
                    + "&oauth_token="+ACCESS_TOKEN
                    + "&oauth_version=1.0"
    
                    ;
            String baseString = host_url+params;
            String signingKey = CONSUMER_SECRET+"&"+AUTH_TOKEN_SECRET;
            VIPLogger.info(TAG, "base string: " + baseString);
            String lSignature = computeHmac(baseString, signingKey);
            VIPLogger.info(TAG, "signature: " + lSignature);
            //lSignature = encode(lSignature);
            VIPLogger.info(TAG, "signature enacoded: " + lSignature);
    
            String lRequestUrl = host_url
                                + "?realm=yahooapis.com"
                                + "&oauth_consumer_key="+CONSUMER_KEY
                                + "&oauth_nonce="+nonce
                                + "&oauth_signature_method=HMAC-SHA1"
                                + "&oauth_timestamp="+timeStamp
                                + "&oauth_token="+ACCESS_TOKEN
                                + "&oauth_version=1.0"
                                + "&oauth_signature="+lSignature
                                ;
            VIPLogger.info(TAG, lRequestUrl.substring(1202));
            HttpGet httpget = new HttpGet(lRequestUrl);
            ResponseHandler<String> responseHandler = new BasicResponseHandler();
            String responseBody = httpclient.execute(httpget, responseHandler);
    
            VIPLogger.info(TAG, "contacts response: " + responseBody);
        }catch(Exception e){
            e.printStackTrace();
            VIPLogger.error(TAG, "error while fetching user contacts");
        }
    
    
    
    }
    
    public String computeHmac(String baseString, String key) {
        try {
            Mac mac = Mac.getInstance("HmacSHA1");
            SecretKeySpec signingKey = new SecretKeySpec(key.getBytes("UTF-8"),
                    "HMAC-SHA1");
            mac.init(signingKey);
            byte[] digest = mac.doFinal(baseString.getBytes());
            String result = Base64.encodeToString(digest, Base64.URL_SAFE);
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            VIPLogger.error(TAG, "error while generating sha");
        }
        return null;
    
    }
    
    public String encodeURIComponent(final String value) {
        if (value == null) {
            return "";
        }
    
        try {
            return URLEncoder.encode(value, "utf-8")
                    // OAuth encodes some characters differently:
                    .replace("+", "%20").replace("*", "%2A")
                    .replace("%7E", "~");
            // This could be done faster with more hand-crafted code.
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }
    
    
        public  String encode(String input) {
            StringBuilder resultStr = new StringBuilder();
            for (char ch : input.toCharArray()) {
                if (isUnsafe(ch)) {
                    resultStr.append('%');
                    resultStr.append(toHex(ch / 16));
                    resultStr.append(toHex(ch % 16));
                } else {
                    resultStr.append(ch);
                }
            }
            return resultStr.toString().trim();
        }
    
        private  char toHex(int ch) {
            return (char) (ch < 10 ? '0' + ch : 'A' + ch - 10);
        }
    
        private  boolean isUnsafe(char ch) {
            if (ch > 128 || ch < 0)
                return true;
            return " %$&+,/:;=?@<>#%".indexOf(ch) >= 0;
        }
    
    0

Recent Posts

in Contacts