这是我获取 oauth 令牌并为 vimeo 授权我的应用程序的代码。这工作正常:
WebView webview = new WebView(this);
webview.getSettings().setJavaScriptEnabled(true);
webview.setVisibility(View.VISIBLE);
setContentView(webview);
Log.i(TAG, "Retrieving request token from Vimeo servers");
try {
final OAuthHmacSigner signer = new OAuthHmacSigner();
signer.clientSharedSecret = Constants.CONSUMER_SECRET_VIMEO;
OAuthGetTemporaryToken temporaryToken = new OAuthGetTemporaryToken(Constants.REQUEST_URL_VIMEO);
temporaryToken.transport = new ApacheHttpTransport();
temporaryToken.signer = signer;
temporaryToken.consumerKey = Constants.CONSUMER_KEY_VIMEO;
temporaryToken.callback = Constants.OAUTH_CALLBACK_URL;
OAuthCredentialsResponse tempCredentials = temporaryToken.execute();
signer.tokenSharedSecret = tempCredentials.tokenSecret;
OAuthAuthorizeTemporaryTokenUrl authorizeUrl = new OAuthAuthorizeTemporaryTokenUrl(Constants.AUTHORIZE_URL_VIMEO);
authorizeUrl.temporaryToken = tempCredentials.token;
String authorizationUrl = authorizeUrl.build();
Log.d("urlop", authorizationUrl);
/* WebViewClient must be set BEFORE calling loadUrl! */
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url,Bitmap bitmap) {
System.out.println("onPageStarted : " + url);
}
@Override
public void onPageFinished(WebView view, String url)
{
Log.d("url", url);
if (url.startsWith(Constants.OAUTH_CALLBACK_URL)) {
try {
if (url.indexOf("oauth_token=")!=-1) {
String requestToken = extractParamFromUrl(url,"oauth_token");
String verifier= extractParamFromUrl(url,"oauth_verifier");
signer.clientSharedSecret = Constants.CONSUMER_SECRET;
OAuthGetAccessToken accessToken = new OAuthGetAccessToken(Constants.ACCESS_URL);
accessToken.transport = new ApacheHttpTransport();
Log.d("abc", "");
accessToken.temporaryToken = requestToken;
Log.d("abc", accessToken.temporaryToken);
accessToken.signer = signer;
accessToken.consumerKey = Constants.CONSUMER_KEY;
accessToken.verifier = verifier;
Log.d("abc", accessToken.verifier);
OAuthCredentialsResponse credentials = accessToken.execute();
signer.tokenSharedSecret = credentials.tokenSecret;
Log.d("abc", signer.tokenSharedSecret);
CredentialStore credentialStore = new SharedPreferencesCredentialStore(prefs);
credentialStore.write(new String[] {credentials.token,credentials.tokenSecret});
view.setVisibility(View.INVISIBLE);
performApiCall();
// startActivity(new Intent(OAuthAccessTokenActivityVimeo.this,Vimeo.class));
}
else if (url.indexOf("error=")!=-1)
{
view.setVisibility(View.INVISIBLE);
new SharedPreferencesCredentialStore(prefs).clearCredentials();
startActivity(new Intent(OAuthAccessTokenActivityVimeo.this,MainMenu.class));
}
} catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("onPageFinished : " + url);
}
private String extractParamFromUrl(String url,String paramName)
{
String queryString = url.substring(url.indexOf("?", 0)+1,url.length());
QueryStringParser queryStringParser = new QueryStringParser(queryString);
return queryStringParser.getQueryParamValue(paramName);
}
});
webview.loadUrl(authorizationUrl);
} catch (Exception ex) {
ex.printStackTrace();
}
}
但是,performApiCall()
我需要这样做:
String url = String.format("http://vimeo.com/api/rest/v2&format=json&full_response=1&method=vimeo.videos.search&oauth_consumer_key=%s&oauth_nonce=fb86e833df995307290763917343ae19&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1350908218&oauth_version=1.0&per_page=20&query=umar&sort=newest&summary_response=1",
Constants.CONSUMER_KEY
);
我怎样才能得到oauth_nonce
,oauth_timestamp
和oauth_signature
?