Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

Youtube upload videos programmatically

$
0
0

i have for the passed 4 days tried to upload to youtube videos but i have failed please help me .

package com.example.testyoutube;import java.io.File;import java.io.IOException;import java.net.MalformedURLException;import java.net.URL;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import com.google.gdata.client.youtube.YouTubeService;import com.google.gdata.data.media.MediaFileSource;import com.google.gdata.data.media.mediarss.MediaCategory;import com.google.gdata.data.media.mediarss.MediaDescription;import com.google.gdata.data.media.mediarss.MediaKeywords;import com.google.gdata.data.media.mediarss.MediaTitle;import com.google.gdata.data.youtube.VideoEntry;import com.google.gdata.data.youtube.YouTubeMediaGroup;import com.google.gdata.data.youtube.YouTubeNamespace;import com.google.gdata.util.AuthenticationException;import com.google.gdata.util.ServiceException;public class MainActivity extends Activity {private Button button;private YouTubeService service;@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    button = (Button) findViewById(R.id.button);    button.setOnClickListener(new OnClickListener() {        @Override        public void onClick(View v) {            submitVideo("/storage/emulated/0/Pictures/Hello Camera/VID_20140523_204750.mp4","i have done it ", "Yooooooooo , it works", "fun");        }    });}public void submitVideo(String vName, String vTitle, String vDesc, String vCate) {    String developer_key = "api key"; // Registered developer key    String clientID = "gmailaccount"; // Server's Youtube account    String password = "passwordofgmailaccount"; // Server's Youtube password    service = new YouTubeService(clientID, developer_key); // YouTube Object, we take action by this.    try {        service.setUserCredentials(clientID,password);    } catch (AuthenticationException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    File videoFile = new File( vName ); // The video local file prepare to upload    String VIDEO_UPLOAD_FEED = "http://uploads.gdata.youtube.com/feeds/api/users/default/uploads";    String mediaType = "video/*"; // Serach .flv MIME type may found more    String vKey1 = vCate; // Use same category and keyword    VideoEntry newEntry = new VideoEntry(); // YouTube video object type, they will return this after uploaded    YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup(); // Collect all of the video information    mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME, vCate));    mg.setTitle(new MediaTitle());    mg.getTitle().setPlainTextContent(vTitle);    mg.setDescription(new MediaDescription());    mg.getDescription().setPlainTextContent(vDesc);    mg.setKeywords(new MediaKeywords());    mg.getKeywords().addKeyword(vKey1);    MediaFileSource ms = new MediaFileSource(videoFile, mediaType);    newEntry.setMediaSource(ms);    VideoEntry ve = null;    try {        ve = service.insert(new URL(VIDEO_UPLOAD_FEED), newEntry);    } catch (MalformedURLException e) {        // TODO Auto-generated catch block        e.printStackTrace();    } catch (IOException e) {        // TODO Auto-generated catch block        e.printStackTrace();    } catch (ServiceException e) {        // TODO Auto-generated catch block        e.printStackTrace();    }    if(ve == null){        System.out.println("Submit to youtube fail.");        return ;    }}}

it says that this "service = new YouTubeService(clientID, developer_key);" has error but it does not explain why , please help (or suggest another code please)


Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>