2011-12-28 2 views
1

나는 안드로이드에서 YouTube에 비디오를 업로드하는 응용 프로그램을 작성 중입니다. 안드로이드에서 API를 사용할 수 없다는 것을 알고 있으므로 비디오를 업로드하기 위해 YouTube에 http 게시 요청을 보내야합니다. 여기에 오류가 발생하는 내 코드가 있습니다. 유효하지 않은 내용 - x-www-urlencode 형식의 코드, Content-Type을 application/atom + xml로 사용한 것을 보여주는 코드입니다. charset = UTF-8 그러면 왜 이런 유형의 오류가 발생합니까?이 중 하나를 도울 수 있습니까?YouTube에서 비디오 업로드 - Android

HttpClient client = new DefaultHttpClient(); 
HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin"); 


List<NameValuePair> pairs = new ArrayList<NameValuePair>(); 
pairs.add(new BasicNameValuePair("Content-Type", "application/x-www-form-urlencoded")); 
pairs.add(new BasicNameValuePair("Email", "xxxx")); 
pairs.add(new BasicNameValuePair("Passwd", "xxx")); 
pairs.add(new BasicNameValuePair("service", "youtube")); 
pairs.add(new BasicNameValuePair("source", "YouTubeApp")); 


post.setEntity(new UrlEncodedFormEntity(pairs)); 

HttpResponse response = client.execute(post); 

String textResponse = getResponseBody(response); 
String auth = textResponse.substring(textResponse.lastIndexOf("Auth")); 

builder.setMessage(auth).show(); 

String entry = "<?xml version=\"1.0\"?>" 
    + "<entry xmlns=\"http://www.w3.org/2005/Atom\"" 
    + " xmlns:media=\"http://search.yahoo.com/mrss/\"" 
    + " xmlns:yt=\"http://gdata.youtube.com/schemas/2007\">" 
    + "<media:group>" 
    + "<media:title type=\"plain\">Bad Wedding Toast</media:title>" 
    + "<media:description type=\"plain\">" 
    + "I gave a bad toast at my friend's wedding. Maybe" 
    + "</media:description>" 
    + "<media:category" 
    + " scheme=\"http://gdata.youtube.com/schemas/2007/categories.cat\">People" 
    + "</media:category>" 
    + "<media:keywords>toast, wedding</media:keywords>" 
    + "</media:group>" 
    + "</entry>"; 

StringBuilder sb = new StringBuilder(); 
sb.append("--"); 
sb.append("Content-Type: application/atom+xml; charset=UTF-8"); 
sb.append(entry); 
sb.append("--"); 
sb.append("Content-Type: video/3gpp"); 
sb.append("Content-Transfer-Encoding: binary"); 

       String bodyStart = sb.toString(); 

       File file = new File("/mnt/sdcard/recordvideooutput.3gpp"); 
       FileInputStream fIn = new FileInputStream(file); 
       byte fileBytes[] = new byte[(int) file.length()]; 
       fIn.read(fileBytes); 

      HttpClient client1 = new DefaultHttpClient(); 
      HttpPost post1 = new HttpPost("https://uploads.gdata.youtube.com/feeds/api/users/default/uploads"); 


      List<NameValuePair> pairs1 = new ArrayList<NameValuePair>(); 
      pairs1.add(new BasicNameValuePair("X-GData-Key", "key=xxxxx")); 
      pairs1.add(new BasicNameValuePair("Slug", "/mnt/sdcard/recordvideooutput.3gpp")); 
      pairs1.add(new BasicNameValuePair("Content-Type", "application/atom+xml; charset=UTF-8")); 
      pairs1.add(new BasicNameValuePair("Content-Length", "" + (bodyStart.getBytes().length + fileBytes.length))); 
      pairs1.add(new BasicNameValuePair("Authorization", "GoogleLogin " + auth)); 


post1.setEntity(new UrlEncodedFormEntity(pairs1)); 

response = client1.execute(post1); 

답변

3

안드로이드 애플리케이션 용 API로 API를 변환 할 수 있습니다. 이 링크는 사용자에게 유용 할 수 있습니다. Resources for Mobile Development with YouTube

+0

답장을 보내 주셔서 감사합니다. 답장에 +1을 드리겠습니다. – Anvesh

+0

고맙습니다. – User3

관련 문제