【问题标题】:YouTube Data API v3 Authentification ErrorYouTube 数据 API v3 身份验证错误
【发布时间】:2016-10-08 19:16:00
【问题描述】:

我正在尝试从我的应用程序中访问 YouTube Data 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$1.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;
}

非常感谢任何帮助!

【问题讨论】:

  • 确保您正在运行的密钥库文件(构建 apk)和相同的文件 SHA1 用于创建 API 密钥。
  • @skadoosh 我使用同一个 Keystore 进行签名和生成 API 密钥。
  • 请教一个问题,查询变量是如何声明的??
  • @rainman 是班级里的衍生领域,忘记加了。

标签: android android-youtube-api youtube-data-api


【解决方案1】:

我自己修好了。

我只是使用了错误的 API 密钥。

编辑:

也许我应该提一下,当我使用 browser api key 而不是 android api key 时它可以工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-13
    • 2014-05-04
    • 1970-01-01
    • 1970-01-01
    • 2015-04-05
    • 2015-09-08
    • 2016-05-20
    • 2015-12-02
    相关资源
    最近更新 更多