2016-04-06 4 views
0

私はyoutubeを使用してandroidアプリケーションを作ろうとしています。 URLを使用して動画をアップロードします。 私のコードでは、私は200のHTTPステータスコードと成功メッセージを受け取りましたが、実際にはそれはありません。 どうすれば解決できますか?どのように私はアンドロイドのYouTubeのAPIを使用してビデオをアップロードできますか?

URL url = new URL(urlString); 
      HttpURLConnection conn = (HttpURLConnection)url.openConnection(); 
      conn.setDoInput(true); 
      conn.setDoOutput(true); 
      conn.setUseCaches(false); 
      conn.setRequestMethod("PUT"); 
      conn.setRequestProperty("Authorization", String.format("Bearer %s", access_token)); 
      conn.setRequestProperty("Content-Type", "video/*"); 
      conn.setRequestProperty("Content-Length", ContentLength); 

      File file = new File(path); 

      FileInputStream fis = new FileInputStream(file); 
      DataOutputStream dos = new DataOutputStream(conn.getOutputStream()); 

      int numberBytes = fis.available(); 
      byte bytearray[] = new byte[numberBytes]; 
      Log.e(" FileLength", String.valueOf(bytearray.length)); 
      for(int i = 0; i < bytearray.length; i++) 
       dos.write(bytearray[i]); 
      dos.flush(); 

      fis.close(); 
      dos.close(); 

      int responseCode = conn.getResponseCode(); 
      if(responseCode == 200) { 
       Log.e("ResponseCode", String.valueOf(responseCode)); 

       InputStream is = conn.getInputStream(); 
       ByteArrayOutputStream baos = new ByteArrayOutputStream(); 
       byte[] byteBuffer = new byte[1024]; 
       byte[] byteData = null; 
       int nLength = 0; 
       while((nLength = is.read(byteBuffer, 0, byteBuffer.length)) != -1) { 
        baos.write(byteBuffer, 0, nLength); 
       } 
       byteData = baos.toByteArray(); 

       String response = new String(byteData); 

       Log.e("RESPONSE", response); 
      } 

     } catch(Exception e) { 
      e.printStackTrace(); 
     } 

答えて

関連する問題