Add token to the header of Vimeo API Android

后端 未结 2 1139
春和景丽
春和景丽 2020-12-20 04:04

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

2条回答
  •  清歌不尽
    2020-12-20 04:49

    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();
         }
      }    
    

提交回复
热议问题