我尝试使用YouTubeService连接到Youtube并上传视频,但如果它已到达YouTubeService(Client_ID,Developer_Code),则会全部崩溃
我从这个主题获得了一些代码: video is rotated when upload on youtube, Android
YouTubeService service = new YouTubeService(Client_ID,Developer_key);
try{
service.setUserCredentials("bla@bla.com", "test1234");
} catch (AuthenticationException ex){
Log.e("AuthenticationError",":"+ex.getMessage());
return;
}
我从产品信息中心获得了开发人员密钥,但我不确定客户端ID是什么(我在某处读过它可能是你喜欢的字符串,但我选择了产品信息中心的应用程序名称)。
本守则的其余部分:
File videoFile = new File(mSharedPreferences.getString("output_file", ""));
if(!videoFile.exists()){
Log.e("FileUploadErr","FileNotFound");
return;
}
String mimeType = "video/*";
String videoTitle = "name";
VideoEntry newEntry = new VideoEntry();
YouTubeMediaGroup mg = newEntry.getOrCreateMediaGroup();
mg.addCategory(new MediaCategory(YouTubeNamespace.CATEGORY_SCHEME,"Travel"));
mg.setTitle(new MediaTitle());
mg.getTitle().setPlainTextContent(videoTitle);
mg.setKeywords(new MediaKeywords());
mg.getKeywords().addKeyword("Travel");
mg.setDescription(new MediaDescription());
mg.getDescription().setPlainTextContent(videoTitle);
MediaFileSource ms = new MediaFileSource(videoFile,mimeType);
newEntry.setMediaSource(ms);
try{
VideoEntry createdEntry = service.insert(new URL("http://uploads.gdata.youtube.com/feeds/api/users/default/uploads"), newEntry);
} catch(ServiceException se){
Log.e("UploadVideo",":" + se.getMessage());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
以下是错误:
02-12 15:31:29.492: E/AndroidRuntime(10012): FATAL EXCEPTION: main
02-12 15:31:29.492: E/AndroidRuntime(10012): java.lang.IllegalStateException: Could not execute method of the activity
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.view.View$1.onClick(View.java:2336)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.view.View.performClick(View.java:2731)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.view.View$PerformClick.run(View.java:9387)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.os.Handler.handleCallback(Handler.java:587)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.os.Handler.dispatchMessage(Handler.java:92)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.os.Looper.loop(Looper.java:130)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.app.ActivityThread.main(ActivityThread.java:3694)
02-12 15:31:29.492: E/AndroidRuntime(10012): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 15:31:29.492: E/AndroidRuntime(10012): at java.lang.reflect.Method.invoke(Method.java:507)
02-12 15:31:29.492: E/AndroidRuntime(10012): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
02-12 15:31:29.492: E/AndroidRuntime(10012): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
02-12 15:31:29.492: E/AndroidRuntime(10012): at dalvik.system.NativeStart.main(Native Method)
02-12 15:31:29.492: E/AndroidRuntime(10012): Caused by: java.lang.reflect.InvocationTargetException
02-12 15:31:29.492: E/AndroidRuntime(10012): at java.lang.reflect.Method.invokeNative(Native Method)
02-12 15:31:29.492: E/AndroidRuntime(10012): at java.lang.reflect.Method.invoke(Method.java:507)
02-12 15:31:29.492: E/AndroidRuntime(10012): at android.view.View$1.onClick(View.java:2331)
02-12 15:31:29.492: E/AndroidRuntime(10012): ... 11 more
02-12 15:31:29.492: E/AndroidRuntime(10012): Caused by: java.lang.VerifyError: com.google.gdata.client.media.MediaService
02-12 15:31:29.492: E/AndroidRuntime(10012): at com.atino.bla.ytUpload.uploadToYoutube(ytUpload.java:111)
02-12 15:31:29.492: E/AndroidRuntime(10012): at com.atino.bla.ytUpload.testMethode(ytUpload.java:58)
02-12 15:31:29.492: E/AndroidRuntime(10012): ... 14 more
任何人都知道如何解决这个问题?