YouTube API v3 示例 IllegalArgumentException,Android Studio

YouTube API v3 Sample IllegalArgumentException, Android Studio

我试图在 Android Studio 中简单地 运行 YouTube API v3,并且该应用程序可以正常打开,并带有显示每个功能的按钮列表,但单击任何他们中的一个使应用程序崩溃并出现此错误:java.lang.IllegalArgumentException: Developer key cannot be null or empty。请注意,这不是我的代码,而是来自 YouTube API 示例文件夹中的代码。我能做些什么来解决这个问题吗?谢谢。

这是 "caused by" 显示的 activity,它说它在 DEVELOPER_KEY 行。

/*
 * Copyright 2012 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.examples.youtubeapidemo;

import com.google.android.youtube.player.YouTubeBaseActivity;
import com.google.android.youtube.player.YouTubePlayer;
import com.google.android.youtube.player.YouTubePlayerView;

import android.os.Bundle;

/**
 * A simple YouTube Android API demo application which shows how to create a simple application that
 * displays a YouTube Video in a {@link YouTubePlayerView}.
 * <p>
 * Note, to use a {@link YouTubePlayerView}, your activity must extend {@link YouTubeBaseActivity}.
 */
public class PlayerViewDemoActivity extends YouTubeFailureRecoveryActivity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.playerview_demo);

    YouTubePlayerView youTubeView = (YouTubePlayerView) findViewById(R.id.youtube_view);
    youTubeView.initialize(DeveloperKey.DEVELOPER_KEY, this);
  }

  @Override
  public void onInitializationSuccess(YouTubePlayer.Provider provider, YouTubePlayer player,
      boolean wasRestored) {
    if (!wasRestored) {
      player.cueVideo("wKJ9KzGQq0w");
    }
  }

  @Override
  protected YouTubePlayer.Provider getYouTubePlayerProvider() {
    return (YouTubePlayerView) findViewById(R.id.youtube_view);
  }

}

LOGCAT

 FATAL EXCEPTION: main
    Process: com.examples.youtubeapidemo, PID: 10226
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.examples.youtubeapidemo/com.examples.youtubeapidemo.PlayerViewDemoActivity}: java.lang.IllegalArgumentException: Developer key cannot be null or empty
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2523)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2582)
            at android.app.ActivityThread.access0(ActivityThread.java:174)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5731)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)
     Caused by: java.lang.IllegalArgumentException: Developer key cannot be null or empty
            at com.google.android.youtube.player.internal.ab.a(Unknown Source)
            at com.google.android.youtube.player.YouTubePlayerView.initialize(Unknown Source)
            at com.examples.youtubeapidemo.PlayerViewDemoActivity.onCreate(PlayerViewDemoActivity.java:39)
            at android.app.Activity.performCreate(Activity.java:5580)
            at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
            at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2487)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2582)
            at android.app.ActivityThread.access0(ActivityThread.java:174)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1321)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5731)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
            at dalvik.system.NativeStart.main(Native Method)

您需要按照步骤 YouTube Api 进行操作。 检查第 4 步。