Note that there are some explanatory texts on larger screens.

plurals
  1. POhelp needed in importing yahoo contacts to my page through play framework
    primarykey
    data
    text
    <p>I am working in Play framework and I am trying to import yahoo contacts.</p> <p>I have cleared the yahoo authentication api's to get the access_token and guid. </p> <p>With that, when I try to import the contacts using <a href="http://social.yahooapis.com/v1/user/" rel="nofollow">http://social.yahooapis.com/v1/user/</a>{guid}/contacts with the auth parameters, I am getting the connection timeout exception in my page and log.</p> <p>When I paste the same contact url being generated through the code in the browser, I am getting as signature_invalid</p> <p>I hope I have followed all the stuffs mentioned in the yahoo api dev notes to create the oauth_signature, but still I am not getting it.</p> <p>Can anyone help me on this please?</p> <p>Controller code for generating signature - </p> <p>public class Yahoo {</p> <pre><code> private static String token = ""; private static String currentUrl = ""; private static String verifier = ""; private static String tokenSecret = ""; private static String accessToken = ""; private static String yahooGuid = ""; public Yahoo(){ } /** * Requests access to the Yahoo API for request token. * @return True if the request is successful, false if not. */ public static Yahoo authorize() { Session session = Session.current(); if(session.contains("authorized") &amp;&amp; session.get("authorized").equals("0")){ session.put("authorized", "1"); String url = getRequestTokenUrl(); WS.WSRequest request = WS.url(url); Logger.info("Yahoo: Create request to get request token'%s'", request.url); WS.HttpResponse response = request.get(); Logger.info("Yahoo: Token response status is %d", response.getStatus()); if (response.getStatus() == 200){ String[] pairs = response.getString().split("&amp;"); String[] tokenSecret = pairs[1].split("="); Yahoo.tokenSecret = tokenSecret[1]; for (String pair : pairs) { String[] kv = pair.split("="); if (kv.length != 2) { break; } else { if (kv[0].equals("oauth_token")) { Yahoo.token = kv[1]; } } } Logger.info("level 1 - yahoo token = %s, secret = %s",Yahoo.token, Yahoo.tokenSecret); } } return null; } /** * Requests access to the Yahoo API for access token. * @return True if the request is successful, false if not. */ public static Yahoo getAccessToken(){ String url = getAccessTokenUrl(); WS.WSRequest request = WS.url(url); Logger.info("Yahoo: Create request to get Access token'%s'", request.url); WS.HttpResponse response = request.get(); Logger.info("Yahoo: Token response status is %d", response.getStatus()); if (response.getStatus() == 200){ String[] pairs = response.getString().split("&amp;"); String[] guidPair = pairs[5].split("="); String[] tokenSecret = pairs[1].split("="); Yahoo.tokenSecret = tokenSecret[1]; yahooGuid = guidPair[1]; for (String pair : pairs) { String[] kv = pair.split("="); if (kv.length != 2) { break; } else { if (kv[0].equals("oauth_token")) { Yahoo.accessToken = kv[1]; } } } Logger.info("level 3 - yahoo token = %s, secret = %s, guid = %s",Yahoo.accessToken, Yahoo.tokenSecret, Yahoo.yahooGuid); } return null; } /** * Requests Signature * @return String */ public static String getBaseSignature(){ String signature = ""; String data = generateBaseString(); String key = keyString(); Logger.info("key : %s",key); try { SecretKeySpec signingKey = new SecretKeySpec(key.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(signingKey); byte[] rawHmac = mac.doFinal(data.getBytes()); signature = new String(Base64.encode(rawHmac)); signature = java.net.URLEncoder.encode(signature, "ISO-8859-1"); Logger.info("Signature=%s", signature); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return signature; } /** * Requests access to the Yahoo API for getting contacts. * */ public static void getContacts(){ String url = getContactUrl(); WS.WSRequest request = WS.url(url); Logger.info("Yahoo: Create request to get Contacts '%s'", request.url); WS.HttpResponse response = request.get(); Logger.info("Yahoo: Token response status is %d", response.getStatus()); if (response.getStatus() == 200){ String[] pairs = response.getString().split("&amp;"); for(int i=0;i&lt;pairs.length;i++){ Logger.info("%s", pairs[i]); } }else { //errors contains a JSON response JsonParser parser = new JsonParser(); JsonObject message = parser.parse(response.getString()).getAsJsonObject(); Logger.error("Yahoo: Could not get token (status %d): %s", response.getStatus(), message.get("message").getAsString()); } } public static String generateBaseString(){ String baseString = getBaseUrl(); Logger.info("token secret : %s",tokenSecret); Logger.info("base url : %s",baseString); Logger.info("callback url : %s",getCallBackUrl().toString().split("oauth_token")[0].replace('?', '\0')); String returnString = ""; try { returnString = java.net.URLEncoder.encode("GET", "ISO-8859-1") + "&amp;" + java.net.URLEncoder.encode("http://social.yahooapis.com/v1/user/"+yahooGuid+"/contacts", "ISO-8859-1") + "&amp;" + java.net.URLEncoder.encode(baseString, "ISO-8859-1"); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } Logger.info("Yahoo: Base string: %s",returnString); return returnString; } public static String keyString(){ String consumerSecret = encodeString(getConsumerSecret()); String tokenSec = encodeString(tokenSecret); String keyString = consumerSecret + encodeString("&amp;") + tokenSec; return keyString; } public static String encodeString(String msgString){ String msg = ""; try { msg = java.net.URLEncoder.encode(msgString.toString(), "ISO-8859-1"); Logger.info("encode=%s", msg); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } return msg; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload