1

メッセンジャーに Yahoo SDK を使用しようとしています。パーツ リクエスト コードを取得していますが、認証コードを取得していません。このサイトの手順に従っています

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();
    }
}
4

0 に答える 0