问题
First of all, sorry for my english, thanks if you edit my question. I need to use my admin account to access for videos on my app. So i must send my token on the header, the docs said:
curl -H "Authorization: bearer OAUTH_TOKEN" https://api.vimeo.com
But i cant do this on Java, this is my method:
public Call fetchContent(String uri, CacheControl cacheControl, ModelCallback callback, @Nullable String query, @Nullable Map refinementMap, @Nullable String fieldFilter)
回答1:
You can do this with version 1.0.1 of the vimeo-networking library. If you refer to the new section in the README as well as the sample app, it will cover how to initialize the VimeoClient
instance with an oAuth Token (or "access token") provided by the developer console.
VimeoClient.initialize(new Configuration.Builder(<accessToken>).build());
You can alternately initialize the builder with the client id and client secret and then set the access token on the builder with setAccessToken(<accessToken>)
if you want to also allow for code grant authentication.
Setting this access token on the builder will default all requests to use that token. If you've provide the client id and client secret, then users of your app could authenticate with a code grant authentication. This will overwrite your initially provided "access token" and all future requests will use their token.
Full disclosure: I'm one of the authors of this library. We also highly encourage any issues or feature requests to be filed here.
回答2:
Use HttpURLConnection and pass OAUTH_TOKEN in the header
String oAuthToken = "your-token";
HttpURLConnection urlConnection = null;
URL vimeoURL = new URL("https://api.vimeo.com");
try {
urlConnection = (HttpURLConnection) vimeoURL.openConnection();
// set authentication
String auth = "Bearer " + oAuthToken;
urlConnection.setRequestProperty("Authorization", auth.trim());
// set request method
urlConnection.setRequestMethod("GET");
if (urlConnection.getResponseCode() == HttpURLConnection.HTTP_OK) {
// do something
}
} catch (Exception e) {// append e
// do something
} finally {
if (urlConnection != null) {// close connection
urlConnection.disconnect();
}
}
来源:https://stackoverflow.com/questions/36018865/add-token-to-the-header-of-vimeo-api-android