我正在尝试授权LinkedIn应用将我的Android应用中的状态发布到linkedin。但是当我点击授权时,我的网页浏览中没有任何内容。
这是我的OwnAuthLinkPage.java:
public class OwnOuthLinkPage extends Activity implements SoapClient {
/** Called when the activity is first created. */
Button b;
WebView wb;
String ftoken,verifire,outh_token,verifire2,requesttokensecret,urlM,OuthT;
CookieManager cookieManager ;
public static SharedPreferences prefs;
public static Editor e;
private static final String API_KEY = "API_KEY_HERE";
//This is the private api key of our application
private static final String SECRET_KEY = "SECRET_KEY_HERE";
//This is any string we want to use. This will be used for avoid CSRF attacks. You can generate one here: http://strongpasswordgenerator.com/
private static final String STATE = "STATE_HERE";
//This is the url that LinkedIn Auth process will redirect to. We can put whatever we want that starts with http:// or https:// .
//We use a made up url that we will intercept when redirecting. Avoid Uppercases.
private static final String REDIRECT_URI = "http://smartprotech.com/1Push/WebService1.asmx";
/*********************************************/
//These are constants used for build the urls
private static final String AUTHORIZATION_URL = "https://www.linkedin.com/uas/oauth2/authorization";
private static final String ACCESS_TOKEN_URL = "https://www.linkedin.com/uas/oauth2/accessToken";
private static final String SECRET_KEY_PARAM = "client_secret";
private static final String RESPONSE_TYPE_PARAM = "response_type";
private static final String GRANT_TYPE_PARAM = "grant_type";
private static final String GRANT_TYPE = "authorization_code";
private static final String RESPONSE_TYPE_VALUE ="code";
private static final String CLIENT_ID_PARAM = "client_id";
private static final String STATE_PARAM = "state";
private static final String REDIRECT_URI_PARAM = "redirect_uri";
/*---------------------------------------*/
private static final String QUESTION_MARK = "?";
private static final String AMPERSAND = "&";
private static final String EQUALS = "=";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.linkdin);
getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
wb= (WebView)findViewById(R.id.webv);
final Activity OwnOuthLinkPage = this;
cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
String authUrl = getAuthorizationUrl();
wb.loadUrl(authUrl);
wb.setWebViewClient(new HelloWebViewClient());
wb.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
//Make the bar disappear after URL is loaded, and changes string to Loading...
OwnOuthLinkPage.setTitle("Loading...");
OwnOuthLinkPage.setProgress(progress * 100); //Make the bar disappear after URL is loaded
// Return the app name after finish loading
if(progress == 100)
OwnOuthLinkPage.setTitle(R.string.app_name);
}
});
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.equalsIgnoreCase("http://smartprotech.com/1Push/WebService1.asmx"))
{
finish();
}
view.loadUrl(url);
try{
StringTokenizer t = new StringTokenizer(url,"=");
String s1 = t.nextToken();
String tokenHint = t.nextToken();//token
verifire = t.nextToken();//verifire
StringTokenizer t2 = new StringTokenizer(tokenHint,"&");
ftoken = t2.nextToken();
ftoken = ftoken.replace("oauth_token=","");
if(!verifire.equalsIgnoreCase("uas-continue")){
StringTokenizer cookies = new StringTokenizer(cookieManager.getCookie("http://smartprotech.com/1Push/Default.aspx"),";");
/* outh_token = cookies.nextToken();
verifire2 = cookies.nextToken();*/
requesttokensecret = cookies.nextToken();
requesttokensecret = cookies.nextToken();
requesttokensecret = requesttokensecret.replace(" TOKENSECREAT=", "");
// System.out.println("*secret**"+reqToken.replace(" requesttoken=", ""));
getToken();
}
}
catch(Exception e){}
return true;
}
}
/************************************************
* making SOAP request for getting nearby values.
************************************************/
public void getToken() {
SoapObject request = new SoapObject("http://tempuri.org/",
"getAccessTS");
request.addProperty("oauth_token", ftoken );
request.addProperty("oauth_Tokensecret",requesttokensecret );
request.addProperty("oauth_verifier",verifire);
SoapConnection connection = new SoapConnection((SoapClient) this, url,
"http://tempuri.org/getAccessTS");
connection.requestWith(request);
}
private static String getAccessTokenUrl(String authorizationToken){
return ACCESS_TOKEN_URL
+QUESTION_MARK
+GRANT_TYPE_PARAM+EQUALS+GRANT_TYPE
+AMPERSAND
+RESPONSE_TYPE_VALUE+EQUALS+authorizationToken
+AMPERSAND
+CLIENT_ID_PARAM+EQUALS+API_KEY
+AMPERSAND
+REDIRECT_URI_PARAM+EQUALS+REDIRECT_URI
+AMPERSAND
+SECRET_KEY_PARAM+EQUALS+SECRET_KEY;
}
/**
* Method that generates the url for get the authorization token from the Service
* @return Url
*/
private static String getAuthorizationUrl(){
return AUTHORIZATION_URL
+QUESTION_MARK+RESPONSE_TYPE_PARAM+EQUALS+RESPONSE_TYPE_VALUE
+AMPERSAND+CLIENT_ID_PARAM+EQUALS+API_KEY
+AMPERSAND+STATE_PARAM+EQUALS+STATE
+AMPERSAND+REDIRECT_URI_PARAM+EQUALS+REDIRECT_URI;
}
@Override
public void success(Object result) {
//SoapObject sobj = (SoapObject) result;
String accessToken,accessSecret;
StringTokenizer t2 = new StringTokenizer(result.toString(),";;");
accessToken = t2.nextToken();
accessSecret = t2.nextToken();
OwnOuthLinkPage.e = prefs.edit();
e.putString("Token", accessToken.replace("AccessToken=", ""));
e.putString("TokenSecret", accessSecret.replace("AccessTokenSecret =", ""));
e.putString("Verifire", verifire);
e.commit();
/* Intent i = new Intent(getApplicationContext(),Main.class);
startActivity(i);*/
finish();
}
@Override
public void error(Object error) {
System.out.println("*******Fail******" + error);
}
}
我无法解决。请帮忙。!