如何从我的应用程序 android 上传视频到 youtube?[英] how to upload a video to youtube from my app android?

问题描述

我正在尝试将视频从我的应用上传到 youtube.我找到了很多参考资料,但所有这些首先在设备上打开 youtube 应用程序,然后从该应用程序上传视频,我想直接上传而不打开 youtube 应用程序.但参考显示为 webview 通过传递 youtube.so 的 URL 打开任何人对此有想法,请帮助我.

任何简单的示例代码,因为项目结束时间.

推荐答案

以下是对我有帮助的代码 请尝试一下,对你有用

public class MainActivity extends YouTubeBaseActivity implements YouTubePlayer.OnInitializedListener {
    Intent intent;
    private static final int SELECT_VIDEO_REQUEST = 1000;
//  static private final String DEVELOPER_KEY = " ";
    static private final String DEVELOPER_KEY ="YOUR API KEY";
    static private final String VIDEO_ID = "qVIwHGI2e1U";
    //static private final String VIDEO_ID ="";
    @Override     
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(DEVELOPER_KEY, this);
    Button click = (Button) findViewById(R.id.button2);
     click.setOnClickListener(onClickListener);
    }
   private OnClickListener onClickListener = new OnClickListener() {

                 @Override
                 public void onClick(View v) {
                     intent = new Intent(android.content.Intent.ACTION_PICK);
                     intent.setType( "video/*");
                       startActivityForResult(intent,SELECT_VIDEO_REQUEST);     
                 }};
                @Override
                public void onInitializationFailure(Provider provider, YouTubeInitializationResult error) {
                    Toast.makeText(this, "Oh no! "+error.toString(), Toast.LENGTH_LONG).show();
                }

                @Override
                public void onInitializationSuccess(Provider provider, YouTubePlayer player, boolean wasRestored) {
                    player.loadVideo("VIDEO_ID");

                    //player.loadVideo("");
                }




@Override
  protected void onActivityResult(int requestCode, int resultCode, Intent returnedIntent) {
    if (resultCode == RESULT_OK) {
      switch (requestCode) {
        case SELECT_VIDEO_REQUEST:
          Intent intent = YouTubeIntents.createUploadIntent(this, returnedIntent.getData());
          startActivity(intent);
          break;
      }
    }
    super.onActivityResult(requestCode, resultCode, returnedIntent);
  }

public static String getVideoId() {
    return VIDEO_ID;
}}

其他推荐答案

YouTube Direct LiteAndroid 版展示了最佳方式.

查看更多