【问题标题】:How can i upload video using android youtube api?如何使用 android youtube api 上传视频?
【发布时间】:2016-04-06 09:28:33
【问题描述】:

我正在尝试使用 youtube 制作一个 Android 应用程序。 我想使用 URL 上传视频。 使用我的代码,我收到了 200 个 http 状态代码和成功消息,但实际上没有。 我该如何解决?

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

【问题讨论】:

    标签: android youtube-api youtube-data-api


    【解决方案1】:

    使用这个library project

    该代码是用于捕获视频、上传到 YouTube、

    的 Android 操作系统应用程序的参考实现

    详细回答:uploading using above library project

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      • 2011-05-13
      • 1970-01-01
      • 2014-12-26
      • 1970-01-01
      • 2017-05-16
      相关资源
      最近更新 更多