YouTube 数据 API v3 身份验证错误

YouTube Data API v3 Authentification Error

我正在尝试从我的应用程序中访问 YouTube 数据 API v3,以从特定频道获取一些视频。我创建了一个 API 密钥并插入了我的包名和 SHA-1 指纹。但是,它不起作用。

这是错误:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
   "code" : 403,
   "errors" : [ {
       "domain" : "usageLimits",
       "message" : "The Android package name and signing-certificate fingerprint, null and null, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions.",
 "reason" : "ipRefererBlocked",
 "extendedHelp" : "https://console.developers.google.com/apis/credentials?project=1097633804344"
   } ],
       "message" : "The Android package name and signing-certificate fingerprint, null and null, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions."
 }
 at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:113)
 at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(AbstractGoogleJsonClientRequest.java:40)
 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.interceptResponse(AbstractGoogleClientRequest.java:321)
 at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:1065)
 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:419)
 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.executeUnparsed(AbstractGoogleClientRequest.java:352)
 at com.google.api.client.googleapis.services.AbstractGoogleClientRequest.execute(AbstractGoogleClientRequest.java:469)
 at de.axelrindle.youtubeapitest.YoutubeConnector.fetchVideoIDS(YoutubeConnector.java:59)
 at de.axelrindle.youtubeapitest.util.VideoIDFetcher.fetchVideoIDS(VideoIDFetcher.java:62)
 at de.axelrindle.youtubeapitest.InitService.onHandleIntent(InitService.java:57)
 at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:66)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:148)
 at android.os.HandlerThread.run(HandlerThread.java:61)

这是发送请求的代码:

YoutubeConnector.class

public YoutubeConnector(Context context) {
    this.context = context;
    youTube = new YouTube.Builder(new NetHttpTransport(), new JacksonFactory(), new HttpRequestInitializer() {
        @Override
        public void initialize(HttpRequest request) throws IOException {}
    }).setApplicationName("YouTube Data API v3 Test").build();

    try {
        query = youTube.search().list("id,snippet");
        query.setKey(DevKey.YOUTUBE_API);
        query.setType("video");
        query.setFields("items(id/videoId,snippet/title,snippet/description,snippet/thumbnails/default/url)");
        query.setChannelId("UC3ifTl5zKiCAhHIBQYcaTeg");
        query.setMaxResults(maxResults);
    } catch (IOException e) {
        Log.e("YoutubeConnector", "Failed to connect to YouTube: " + e.getMessage());
    }
}

public List<String> fetchVideoIDS() {

    List<String> ids = new ArrayList<>();
    maxResults += 10;

    try {
        SearchListResponse response = query.execute();
        List<SearchResult> results = response.getItems();

        for (SearchResult result : results) {
            ids.add(result.getId().getVideoId());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

    return ids;
}

任何帮助都非常感谢

自己修好了

我只是用错了 API 键。

编辑:

也许我应该提到当我使用 浏览器 api 键 而不是 android [=26= 时它起作用了] 键.