Click here to Skip to main content
15,905,971 members
Home / Discussions / Java
   

Java

 
GeneralRe: project Pin
Nagy Vilmos27-Jun-11 21:20
professionalNagy Vilmos27-Jun-11 21:20 
QuestionRegex to find an alphanumeric sequence in a block of text. Pin
kartikdasani22-Jun-11 19:24
kartikdasani22-Jun-11 19:24 
AnswerRe: Regex to find an alphanumeric sequence in a block of text. Pin
Peter_in_278022-Jun-11 19:50
professionalPeter_in_278022-Jun-11 19:50 
QuestionConfused with making "Balanced" Binary Search Tree - JAVA (Netbeans) Pin
D315822-Jun-11 6:13
D315822-Jun-11 6:13 
AnswerRe: Confused with making "Balanced" Binary Search Tree - JAVA (Netbeans) Pin
David Skelly23-Jun-11 1:57
David Skelly23-Jun-11 1:57 
GeneralRe: Confused with making "Balanced" Binary Search Tree - JAVA (Netbeans) Pin
D315823-Jun-11 6:05
D315823-Jun-11 6:05 
GeneralRe: Confused with making "Balanced" Binary Search Tree - JAVA (Netbeans) Pin
quangson9124-Jun-11 21:46
quangson9124-Jun-11 21:46 
QuestionHelp me! Get profile user of yahoo [modified] Pin
langthuan21-Jun-11 19:44
langthuan21-Jun-11 19:44 
Bug is:</b> <b>{"error":{"lang":"en-US","description":"Please provide valid credentials. OAuth oauth_problem=\"signature_invalid\", realm=\"yahooapis.com\""}},



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 = "dj0yJmk9RzNIMEI3NXNMTXdPJmQ9WVdrOVRWQnZjREZvTlRZbWNHbzlPRGs0T0RZM05UWXkmcz1jb25zdW1lcnNlY3JldCZ4PWM0";
	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);
		
	}
}
</code>


modified on Wednesday, June 22, 2011 3:05 AM

AnswerRe: Help me! Get profile user of yahoo Pin
TorstenH.21-Jun-11 20:19
TorstenH.21-Jun-11 20:19 
GeneralRe: Help me! Get profile user of yahoo Pin
langthuan21-Jun-11 20:51
langthuan21-Jun-11 20:51 
GeneralRe: Help me! Get profile user of yahoo Pin
TorstenH.21-Jun-11 21:06
TorstenH.21-Jun-11 21:06 
GeneralRe: Help me! Get profile user of yahoo Pin
langthuan21-Jun-11 21:23
langthuan21-Jun-11 21:23 
GeneralRe: Help me! Get profile user of yahoo Pin
TorstenH.21-Jun-11 22:51
TorstenH.21-Jun-11 22:51 
AnswerRe: Help me! Get profile user of yahoo Pin
Nagy Vilmos21-Jun-11 22:20
professionalNagy Vilmos21-Jun-11 22:20 
AnswerRe: Help me! Get profile user of yahoo Pin
Shameel4-Jul-11 8:18
professionalShameel4-Jul-11 8:18 
QuestionHelp Erro Logic Code of java project Pin
HeartsFrozen18-Jun-11 21:26
HeartsFrozen18-Jun-11 21:26 
AnswerRe: Help Erro Logic Code of java project Pin
Richard MacCutchan18-Jun-11 21:52
mveRichard MacCutchan18-Jun-11 21:52 
AnswerRe: Help Erro Logic Code of java project Pin
HeartsFrozen18-Jun-11 22:08
HeartsFrozen18-Jun-11 22:08 
QuestionHow to capture image writing Java code Pin
Ravindra Thakare16-Jun-11 21:18
Ravindra Thakare16-Jun-11 21:18 
AnswerRe: How to capture image writing Java code Pin
Nagy Vilmos16-Jun-11 22:16
professionalNagy Vilmos16-Jun-11 22:16 
QuestionDatabase question Pin
TheMrProgrammer16-Jun-11 7:01
TheMrProgrammer16-Jun-11 7:01 
AnswerRe: Database question Pin
Nagy Vilmos16-Jun-11 22:15
professionalNagy Vilmos16-Jun-11 22:15 
GeneralRe: Database question Pin
jschell17-Jun-11 12:07
jschell17-Jun-11 12:07 
GeneralRe: Database question Pin
Nagy Vilmos17-Jun-11 20:02
professionalNagy Vilmos17-Jun-11 20:02 
GeneralRe: Database question Pin
jschell20-Jun-11 8:06
jschell20-Jun-11 8:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.