1

我尝试使用 YouTubeService 连接到 Youtube 并上传视频,但如果它到达 YouTubeService(Client_ID,Developer_Code) 就会崩溃

我从这个主题得到了一些代码: 视频在 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

有人知道如何解决这个问题吗?

4

0 回答 0