0

Help me! Get profile user of yahoo

Bug is:{"error":{"lang":"en-US","description":"Please provide valid credentials. OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\""}},


CODEBOX
package yahoo.contast.query;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.GeneralSecurityException;

import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
import org.scribe.services.HMACSha1SignatureService;

import sun.misc.BASE64Encoder;

public class Login{

private static final String CONSUMER_KEY = "dj0yJmk9RzNIMEI3NXNMTXdPJmQ9WVdrOVRWQnZjREZvTlRZbWNHbzlPRGs0T0RZM05UWXkmcz1j
b25zdW1lcnNlY3JldCZ4PWM0";
private static String CONSUMER_SECRET = "e2ac48448a54afa7d6eae9033f702e3e6e420011";

public static void main(String[] args) throws Exception {

String userName = ".....@yahoo.com.vn";
String password = "123456";

HttpClient client = new HttpClient();
client.getParams().setParameter(
HttpMethodParams.USER_AGENT,
"Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)");
//login and get request token
PostMethod post = new PostMethod("https://login.yahoo.com/WSLogin /V1/get_auth_token?&login="+userName+"&passwd="+password+"&oauth_consumer_key="+CONSUMER_KEY+"&xoauth_lang_pref=en-us");
post.setDoAuthentication(true);
client.executeMethod(post);
String requestTokent = requestTokent = post.getResponseBodyAsString();
System.out.println(requestTokent);

//get oauth token, oauth_token_secret, oauth_expires_in, oauth_session_handle, oauth_authorization_expires_in, xoauth_yahoo_guid
long timeStamp = System.currentTimeMillis() / 1000;
String[] temp = requestTokent.split("=");
String signatureToken = URLEncoder.encode(CONSUMER_SECRET+"&");
String url = "https://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=plaintext&oauth_version=1.0&oauth_timestamp="+timeStamp+"&oauth_nonce=8B9SaF&oauth_signature="+signatureToken+"&oauth_token="+temp[1]+"";

GetMethod getToken = new GetMethod(url);
client.executeMethod(getToken);
String token = getToken.getResponseBodyAsString();
System.out.println("Token: "+ token);

//parse get parameter response
String param[] = token.split("&");

String oauthTokenSplit[] = param[0].split("=");
String oauthToken = oauthTokenSplit[1];
String ouathTokenSecret = param[1].replace("oauth_token_secret=", "");
String ouathExpriresIn = param[2];
String ouathSessionHandle = param[3].replace("oauth_session_handle=", "");
String ouathAuthoriztion = param[4];
String xouathYahooGuid = param[5].replace("xoauth_yahoo_guid=", "");


//refresh access token
long timeStampRefresh = System.currentTimeMillis() / 1000;
String signatureRefresh = URLEncoder.encode( CONSUMER_SECRET + "&" + ouathTokenSecret );
//refresh access token
String urlRefresh = "https://api.login.yahoo.com/oauth>/v2/get_token?oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=PLAINTEXT&oauth_version=1.0&oauth_timestamp="+timeStampRefresh+"&oauth_nonce=8B9SkF&oauth_signature="+signatureRefresh+"&oauth_token="+oauthToken+"&oauth_session_handle="+ouathSessionHandle+"";
PostMethod refreshToken = new PostMethod(urlRefresh);
client.executeMethod(refreshToken);
String refresh = refreshToken.getResponseBodyAsString();
System.out.println("Token Refresh: "+refresh);

String paramRefresh[] = refresh.split("&");
String oauthTokenRefresh = paramRefresh[0].replace("oauth_token=", "");
String oauthTokenSecretRefresh = paramRefresh[1].replace("oauth_token_secret=", "");
String ouathSessionHandleRefresh = paramRefresh[3].replace("oauth_session_handle=", "");
String guid = paramRefresh[5].replace("xoauth_yahoo_guid=", "");




// bug start here! please you help me


//get profile of user
long profileTimeStamp = System.currentTimeMillis();
profileTimeStamp = profileTimeStamp / 1000;
String baseString = "GET&" + URLEncoder.encode("http://social.yahooapis.com/v1/user/"+guid+"/profile?format=json&oauth_consumer_key="+CONSUMER_KEY+"&oauth_nonce=24829869585&oauth_signature_method=HMAC-SHA1&oauth_timestamp="+profileTimeStamp+"&oauth_token="+oauthTokenRefresh+"&oauth_version=1.0");

HMACSha1SignatureService hmacSha1SignatureService = new HMACSha1SignatureService();
String signatureProfile = hmacSha1SignatureService.getSignature( baseString, CONSUMER_SECRET, oauthTokenSecretRefresh );
signatureProfile = URLEncoder.encode(signatureProfile,"utf-8");

GetMethod profile = new GetMethod("http://social.yahooapis.com/v1/user/"+guid+"/profile?format=json&realm=yahooapis.com&oauth_consumer_key="+CONSUMER_KEY+"&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_timestamp="+profileTimeStamp+"&oauth_nonce=24829869585&oauth_token="+oauthTokenRefresh+"&oauth_signature="+signatureProfile+"");
client.executeMethod(profile);
String profileResponse = profile.getResponseBodyAsString();

System.out.println(profileResponse);

}
}



Exception:

{"error":{"lang":"en-US","description":"Please provide valid credentials. OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\""}}


Here, I'm used Yahoo API get profile information of user. Frist I'm get request token, after I'm used request token get access token and parameter, final I'm used access token and parameter get profile of user. but I've encountered one bug \"signature_invalid\" in the final step.

by
3 Replies
  • are you help me ?
    0
  • There are a lot of Windows Password Recovery and crackers available, which can easily reset your forgotten password, but I have found that Windows Password Recovery Tool 3.0 is the most effective.
    It not only supports XP, 2000, and NT, I have personally tested it with Vista and Windows 7. It works perfectly to reset any local user account to a blank password.
    Source(s):
    Google search: Windows Password Recovery Tool 3.0
    -1

  • I cannot change my computer from California to Arizona.  Help
    0
  • sir/mam,pls
    give me my password.
    im sory mis to password.but seved my monitar.
    so pls send my email sunilsingh222034@yahoo.com
    0

Recent Posts

in YAP