2016-04-06 6 views
0

ich versuche, eine andoide Anwendung mit youtube zu machen. Ich möchte ein Video mit URL hochladen. mit meinen Codes erhielt ich 200 http Statuscode und Erfolgsmeldung, aber eigentlich nicht. Wie kann ich es lösen?Wie kann ich Videos mit Android Youtube API hochladen?

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

Antwort