분류 | 게시판 |
베스트 |
|
유머 |
|
이야기 |
|
이슈 |
|
생활 |
|
취미 |
|
학술 |
|
방송연예 |
|
방송프로그램 |
|
디지털 |
|
스포츠 |
|
야구팀 |
|
게임1 |
|
게임2 |
|
기타 |
|
운영 |
|
임시게시판 |
|
private String uploadMetaData(String filePath, boolean retry) throws IOException { String title = getTitleText(); String description = getDescriptionText(); String category = DEFAULT_VIDEO_CATEGORY; String tags = DEFAULT_VIDEO_TAGS; if (getTagsText() != null && getTagsText().trim().length() != 0) { tags = getTagsText(); } String urlData = "uploadType=resumable&part=snippet,status,contentDetails"; String uploadUrl = INITIAL_UPLOAD_URL + "?" + urlData; URL url = new URL(uploadUrl); HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setRequestProperty("Host", "www.googleapis.com"); urlConnection.setRequestProperty("Authorization", String.format("Bearer %s", accessToken)); urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); urlConnection.setRequestProperty("X-Upload-Content-Type", "video/*"); // urlConnection.setRequestProperty("Content-Length", ); // urlConnection.setRequestProperty("X-Upload-Content-Length", ); urlConnection.setDoOutput(true); String postDataForm = "{\n\"snippet\": {\n\"title\": \"%s\",\n\"description\": \"%s\",\n\"tags\": " + "[\"cool\", \"video\", \"more keywords\"],\n\"categoryId\": 22\n},\n\"status\": " + "{\n\"privacyStatus\": \"public\",\n\"embeddable\": True,\n\"license\": \"youtube\"\n}\n}"; String postData = String.format(postDataForm, title, description, tags); DataOutputStream dos = new DataOutputStream(urlConnection.getOutputStream()); dos.writeBytes(postData); dos.flush(); dos.close(); int responseCode = urlConnection.getResponseCode(); if (responseCode < 200 || responseCode >= 300) { // The response code is 40X if ((responseCode + "").startsWith("4") && retry) { Log.d(LOG_TAG, "retrying to fetch auth token for " + name); // this.clientLoginToken = authorizer.getFreshAuthToken(youTubeName, clientLoginToken); // Try again with fresh token return uploadMetaData(filePath, false); } else { throw new IOException(String.format("response code='%s' (code %d)" + " for %s", urlConnection.getResponseMessage(), responseCode, urlConnection.getURL())); } } Log.d("크르릉", "urlConnection.getHeaderField " + urlConnection.getHeaderField("Location")); return urlConnection.getHeaderField("Location"); }
인데요....
String postDataForm = "{\n\"snippet\": {\n\"title\": \"%s\",\n\"description\": \"%s\",\n\"tags\": " + "[\"cool\", \"video\", \"more keywords\"],\n\"categoryId\": 22\n},\n\"status\": " + "{\n\"privacyStatus\": \"public\",\n\"embeddable\": True,\n\"license\": \"youtube\"\n}\n}"; String postData = String.format(postDataForm, title, description, tags); DataOutputStream dos = new DataOutputStream(urlConnection.getOutputStream()); dos.writeBytes(postData); dos.flush(); dos.close();
이 부분이 없으면 일단 업로드는 되요. 다만 title, description, tags 이런 정보가 업로드 되지 않고 동영상만 업로드 되네요...
(동영상 업로드는 위의 메소드에서 받은 리턴값을 이용해서 다른 메소드에서 처리합니당)
암만 생각해봐도 postDataForm 부분이 잘못된 거 같은데요..... 어케 해야 하는걸까요 ㅜㅜ
어제 저녁부터 새벽까지 저거 하나땜에 고생이네요.... 요리 바꾸고 조리 바꾸고 해봤는데 계속 실패 ㅜㅜ
도움이 필요합니다~
죄송합니다. 댓글 작성은 회원만 가능합니다.