用于YDN api的Http响应代码401

时间:2011-07-08 18:01:57

标签: java android http yahoo-messenger

我正在尝试使用Yahoo SDK for messenger,我正在查找部分请求代码,但我没有获得授权代码。我正在按照本网站的步骤进行操作

http://developer.yahoo.com/messenger/guide/exchangepartforoauthcredentials.html

代码:

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 个答案:

没有答案