gpt4 book ai didi

java - 获取vimeo api的签名

转载 作者:行者123 更新时间:2023-11-29 21:56:54 24 4
gpt4 key购买 nike

这是我获取 oauth token 并为 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_nonceoauth_timestampoauth_signature

最佳答案

  1. 关于 oauth_timestamp:据我所知,您自己设置时间戳为当前时间戳。如果您遇到问题(vimeo 希望时间戳在它认为的当前时间戳之前或之后不超过几秒的差异,请参见 the vimeo forum thread here ),请尝试摆弄您使用的系统时间(例如,服务器时间) .

  2. 关于 oauth_nonce:nonce 值是一个“随机字符串,由客户端唯一生成以允许服务器验证从未发出过请求之前”(The OAuth 1.0 Protocol)。

  3. Re oath_signature:客户端生成自己的签名。来自 The OAuth 1.0 Protocol :

The client declares which signature method is used via the"oauth_signature_method" parameter. It then generates a signature (ora string of an equivalent value) and includes it in the"oauth_signature" parameter. The server verifies the signature asspecified for each method.

简而言之:您不会从某处“获取”这些值,您必须创建它们。

我真的很想推荐给你 The OAuth 1.0 Protocol再一次,它相当容易阅读,应该可以帮助您解决大多数可能遇到的问题:)。

希望这对您有所帮助。

关于java - 获取vimeo api的签名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13012828/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com