开发者

Http response code 401 for YDN apis

I am trying to use Yahoo SDK for messenger, i am geting the part request code but i am not getting the authorization code. I am following the steps from this site

http://developer.yahoo.com/messenger/guide/exchangepartforoa开发者_如何学Cuthcredentials.html

code :

String strurl = "https://login.yahoo.com/WSLogin/V1/get_auth_token?&login=name&passwd=passwd&oauth_consumer_key=dj0yJmk9WnhsVVZvSDhkYTVpJmQ9WVdrOWMwRlVZV0p2TkRnbWNHbzlNVFE0TURJek5qVTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNg";
    URL url;
    try
    {
        System.setProperty("http.keepAlive", "false");
        url = new URL(strurl);
        HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
        InputStream requesttokenstrem = urlConnection.getInputStream();
        String result =  new Scanner(requesttokenstrem).useDelimiter("\\A").next();
        requesttokenstrem.close();
        String[] resultTokens = result.split("=");

         if(null != resultTokens &&  1 <= resultTokens.length)
         {
             String requestToken = resultTokens[1]; 
             System.out.println(requestToken);
String url2 = "https://api.login.yahoo.com/oauth/v2/get_token?"+
             "&oauth_consumer_key=dj0yJmk9WnhsVVZvSDhkYTVpJmQ9WVdrOWMwRlVZV0p2TkRnbWNHbzlNVFE0TURJek5qVTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD0yNg"+
             "&oauth_signature_method=PLAINTEXT"+
             "&oauth_nonce=123456"+
             "&oauth_timestamp="+(System.currentTimeMillis()/1000)+""+
             "&oauth_signature=cd749fd91ef7380e9bebd581a33e708e0d4d42f4"+"%26"+
             "&oauth_verifier=Boasvd78"+
             "&oauth_version=1.0"+
             "&oauth_token="+requestToken;

             getsessionId(url2);
        }
    }
    catch (MalformedURLException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

private void getsessionId(String url)
{
    System.setProperty("http.keepAlive", "false");
    URL getTokenUrlExec;
    try
    {
        getTokenUrlExec = new URL(url);
        HttpsURLConnection connectionGetToken = (HttpsURLConnection) getTokenUrlExec.openConnection();
        String s;
//          if (responseCode == HttpsURLConnection.HTTP_OK) 
//          {
            InputStream in = connectionGetToken.getInputStream();
             byte[] capture = new byte[in.available()];
             int amount = in.read(capture);
             s = new String(capture);
             in.close();
//          }
        int responseCode = connectionGetToken.getResponseCode();
    }
    catch (MalformedURLException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜