8

I'm a new programmer in Android studio.

I am trying to create a button that gets a file location and uploads it to my youtube account:

I succeeded to get a video file's directory in my android code:

File mediaFile = 
    new File(Environment.getExternalStorageDirectory().getAbsolutePath()....)

I added a button that calls UploadToYoutube function.

Now I would like to upload it to my youtube account through the file path I have.

Can someone direct me?

Any help appreciated!

Alon Shmiel
  • 6,753
  • 23
  • 90
  • 138
  • I think it was answered before please check this [answer][1] [1]: http://stackoverflow.com/questions/10246212/android-youtube-upload-video-with-static-username-and-password/10432215#10432215 – Albert Apr 13 '15 at 16:07

2 Answers2

16

My suggestion:

Get Start

Obtaining authorization credentials

Implementing OAuth 2.0 Authentication

YouTube API: Client Libraries

Using google-api-java-client:

Use YouTube Data API (v3)

Sources Examples in

Post a channel bulletin

Create and manage YouTube video caption tracks

Add a featured video

Retrieve my uploads

Create a playlist

Search by keyword

Search by topic

Search by geolocation

Add a channel subscription

Upload a video thumbnail image

Upload a video << Example code in java : )

Update a video

Sevle
  • 3,109
  • 2
  • 19
  • 31
Dexter
  • 566
  • 4
  • 10
0

Here is my working code

        ContentValues content = new ContentValues(4);
        content.put(MediaStore.Video.VideoColumns.DATE_ADDED,
                System.currentTimeMillis() / 1000);
        content.put(MediaStore.Video.Media.MIME_TYPE, "video/mp4");
        content.put(MediaStore.Video.Media.DATA, path);
        ContentResolver resolver = getActivity().getContentResolver();
        Uri uri1 =  Uri.fromFile(new File(path)); 

        Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
        sharingIntent.setType("video/*");
        sharingIntent.setPackage("com.google.android.youtube");
        sharingIntent.putExtra(Intent.EXTRA_TITLE, "Title");
        sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Desc");
        sharingIntent.putExtra(android.content.Intent.EXTRA_STREAM, uri1);
        startActivity(Intent.createChooser(sharingIntent, "Share to"));
user5071155
  • 121
  • 1
  • 2