0

Session request in java

Hello, i am trying to develop a yahoo messenger client for Android. I made the first request for the request token and i have the response .

The RequestToken i get it by sending the username, password and my consumer key.

I don't know very well what to do next... , as i seen in this forum the next step should be the Session Request.

I have this code:

CODE
java.util.Date today = new java.util.Date(); // get the timestamp
long timeStamp = today.getTime();

String sessionUrl = "http://api.login.yahoo.com/v1/session" +
"?oauth_consumer_key=" + "MY KEY IS HERE" +
"&oauth_nonce=" + "24829.2331" +
"&oauth_signature=" + "MY CONSUMER SECRET KEY IS HERE" + "%26" + text.replace("RequestToken=", "") + // here i get the Request token
"&oauth_signature_method=PLAINTEXT" +
"&oauth_timestamp=" + timeStamp +
"&oauth_token=" + text.replace("RequestToken=", "") + // here i get the Request token again
"&oauth_version=1.0" +
"&notifyServerToken=1";


URL urlSession = null;

try {
urlSession = new URL(sessionUrl);
} catch (MalformedURLException ex) {
Log.e("MalformedURLException 1", "" + ex);
}

HttpURLConnection connSes = null;
try {
connSes = (HttpURLConnection) urlSession.openConnection();
} catch (IOException ex) {
Log.e("IOException 1", "" + ex);
}

try {
connSes.setRequestMethod("GET");
} catch (ProtocolException ex) {
Log.e("ProtocolException 1", "" + ex);
}

try {
connSes.connect();
} catch (IOException ex) {
Log.e("IOException 2", "" + ex);
}

InputStream inSess = null;
try {

inSess = connSes.getInputStream();

} catch (IOException ex) {
Log.e("IOException 3", "" + ex);
}

BufferedReader readerSess = new BufferedReader(new InputStreamReader(inSess));

String textSess = "";
try {
textSess = readerSess.readLine();
} catch (IOException ex) {
Log.e("IOException 4", "" + ex);
}

connSes.disconnect();

if (textSess == null){
txt.append("\n " + textSess.charAt(1));
}else {
txt.append("\n NULL");
}


With this code i am getting an null pointer error when i am trying to print the response.
I think that my request is not to good or i am not doing the correct request.

Can anyone help me please, i have read http://developer.yahoo.com/messenger/guide/index.html but i can't understand to much the order of the requests and how to make them.

Thank you very much !

by
5 Replies
  • Me again, i resolved that problem by using HttpClient instead of HttpUrlConnection class to send the request.

    For the first time i tested by this method i've got the "OAuth oauth_problem="token_rejected", realm="yahooapis.com"", after changing some variables from the url i get "Forbiden" - error

    This is the url i send to yahoo:

    CODE
    // class variabiles
    private static final String OAUTH_ACCESS = "https://api.login.yahoo.com/oauth/v2/get_token";

    //private keys (not the real ones)
    private static final String CONSUMER_KEY = dj0yJmkjhsdfkjshdfkcVRNJmQ9WVdrOWNqasdjghasdu8768lNQS0tJnM9Y29uc3VtZXJ8768sadfsa
    dQmeD00ZQ--";
    private static final String CONSUMER_SECRET = "c96e9d78676asd987aded026ea8491ccf3982f";

    String url;
    url = OAUTH_ACCESS;
    url += "?oauth_consumer_key=" + CONSUMER_KEY;
    url += "&oauth_nonce=" + rand.nextDouble(); // a random string
    url += "&oauth_signature=" + CONSUMER_SECRET + "%26";
    url += "&oauth_signature_method=PLAINTEXT";
    url += "&oauth_timestamp=" + timeStamp;
    url += "&oauth_token=" + OAUTH_TOKEN; // the auth token i get from the login request
    url += "&oauth_version=1.0";


    Thank you in advance !
    0
  • Nobody knows how can i do a simple login to yahoo?

    Please help.

    Thenk you!
    0
  • Sorry for double posting but i found some things here http://developer.yahoo.com/oauth/guide/oauth-userauth.html it says that i need the user's authorization to make a session. How can i make a log in without that authorization or how can i do the login if i have a android application and not a web application.

    I don't need code, i need some links that can open my eyes.

    Thank you and sorry for the multi posting but i can't find any edit button.
    0
  • You can also do direct oauth without user going to a page. I think you have done that now, seeing by your other messages in the forum regarding notifications.
    0
  • @Catalin

    I used to get confused with that stuff. Actually OAuth guide pages only give you a view into OAuth using to deal with Yahoo!API and WebServices in common. In some application that need access to user's profile then we will need to do that confirmation.

    Actually, for those who are struggling with Yahoo Messenger, this page is almost sufficient for basic operations such as login / log out / sending & receiving messages: http://developer.yahoo.com/messenger/guide/
    0

Recent Posts

in Messenger IM SDK